简体   繁体   English

如何在ASP.NET MVC 3应用程序中实现共享状态?

[英]How do I implement shared state in an ASP.NET MVC 3 application?

I'm writing a basic RESTful service, and decided I'd use ASP.NET MVC 3 for the task. 我正在编写一个基本的RESTful服务,并决定将ASP.NET MVC 3用于该任务。 My application is going to be responsible for maintaining a persistent connection to a server per user (for now). 我的应用程序将负责维护每个用户与服务器的持久连接(目前)。 I had assumed that Application_Start is the place to register static/shared state (like persistent connections), but after reading the documentation for Unity.MVC3, it appears that each request/response cycle will trigger the creation of services (by calling Application_Start). 我以为Application_Start是注册静态/共享状态(如持久连接)的地方,但是在阅读Unity.MVC3的文档之后,似乎每个请求/响应周期都会触发服务的创建(通过调用Application_Start)。

The documentation I refer to says: 我引用的文档说:

On every request, one UpperCaseService, one LowerCaseService and one ExampleContext are instantiated by DependencyResolver via Unity. 对于每个请求,DependencyResolver会通过Unity实例化一个UpperCaseService,一个LowerCaseService和一个ExampleContext。 At the end of the request, the ExampleContext is automatically disposed 在请求结束时,ExampleContext被自动释放

After reading other documentation, and from what I already assumed, Application_Start would be called per AppDomain spawned (again assumed that this would be in the vicinity of how many cores there are on the server). 在阅读了其他文档之后,并且按照我已经假设的那样,将按每个AppDomain生成的名称调用Application_Start(再次假定这将在服务器上有多少个内核附近)。

So, what would be an effective way of maintaining a set of persistent connections to a server, that survive the request/response phase, and if possible, are shared between all AppDomains that the IIS server has created? 那么,什么是维护与服务器的一组持久连接,在请求/响应阶段中生存并在IIS服务器已创建的所有AppDomain之间共享的有效方法?

It might help to mention that this web service is only going to be consumed by another web site. 可能需要提及的是,该Web服务仅将由另一个网站使用。 It is essentially an Authentication Proxy server, however, in the future, it is going to do a lot more. 它本质上是一个身份验证代理服务器,但是在将来,它将做更多的事情。 Therefore, I can't just cache the response, as future requests will be required, and reauthenticating is not an option. 因此,我不能仅仅缓存响应,因为将来的请求将是必需的,并且重新认证不是一种选择。

If you want to survive AppDomain restarts and share state between multiple ASP.NET applications you will have to go out of the IIS process and store this in a central location that is accessible from all applications. 如果要生存下来,AppDomain将重新启动并在多个ASP.NET应用程序之间共享状态,则必须退出IIS进程,并将其存储在所有应用程序都可以访问的中央位置。 A database is a good candidate. 数据库是一个不错的选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 ASP.NET MVC 应用程序中实现搜索框? - How do I implement a search box in an ASP.NET MVC application? 如何在ASP.NET MVC 2应用程序中实现向导类型的页面导航? - How do I implement wizard type page navigation in an ASP.NET MVC 2 application? 如何在应用程序状态(C#ASP.net MVC)中存储列表〜数组 - How do I store List ~ Array in the Application State (C# ASP.net MVC) 如何在ASP.NET MVC中实现模拟框架? - How do I implement simulated frames in ASP.NET MVC? 如何使用ASP.NET Identity for ASP.NET MVC 5.0实现密码重置? - How do I implement password reset with ASP.NET Identity for ASP.NET MVC 5.0? 如何在ASP.NET MVC应用程序中使用ASP.NET页? - How do I use ASP.NET pages in an ASP.NET MVC application? 如何使用Silverlight实现WCF,同时支持ASP.NET会话状态和SSL? - How do I implement WCF with Silverlight, supporting both ASP.NET session state and SSL? 如何将数据库中的数据添加到 ASP.NET Core MVC (.NET 6) 应用程序中的共享 _Layout.cshtml? - How do you add data from the database to the shared _Layout.cshtml in ASP.NET Core MVC (.NET 6) application? 如何在ASP.NET MVC中实现插页式“加载...”页面? - How do I implement an interstitial “loading…” page in ASP.NET MVC? 如何在 ASP.NET MVC 站点中实施速率限制? - How do I implement rate limiting in an ASP.NET MVC site?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM