当页面不刷新时控制器是否保持状态?
我想在我的控制器中放置两个私有变量。我将在页面加载时通过在前端进行 ajax 调用来获取一些用户 IP 数据来填充这些变量,并填充这些变量。
我能否确保只要不刷新页面(刷新后将再次设置),它们就会在网站的整个用户体验中被填充,或者 MVC 不能以这种方式工作吗?
I want to put two private variables in my controller. I am going to fill these when the page loads by making an ajax call on the front end to get some user IP data, and fill these variables.
Can I be sure that they will be filled throughout the user experience with the site as long as they don't refresh the page (upon refreshed they will be set again), or does MVC not work this way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
mvc是无状态的。句号。
ASP.NET MVC - 状态和体系结构
The mvc is stateless. Fullstop.
ASP.NET MVC - State and Architecture
正如所指出的,MVC 是无状态的。
服务器端存储(例如会话状态下的自定义 DB 或 Asp.Net)之外唯一能够在 GET 请求中幸存下来并可供服务器和客户端使用的数据存储是 cookie。请注意,Cookie 大小是有限的(每个浏览器有所不同 - 每个 Cookie 大约 4K,每个域总计不到 100 个 Cookie/100K)。
As it is pointed out MVC is stateless.
The only data storage outside server side storage (like custom DB or Asp.Net in session state) that survives GET requests and avaialbe for both server and client is cookies. Note that cookie size is limited (vairying per browser - around 4K per cookie, under 100 cookies/100K total per domain).
控制器是无状态的。它不保存已初始化私有变量的值。
Controller is stateless. It doesn't hold the values of initialized private variables.