asp.net-mvc – 无法获得有效的Unity Session Lifetime Manager,
发布时间:2020-12-16 09:41:23 所属栏目:asp.Net 来源:网络整理
导读:我已经阅读并使用Google搜索了所有内容,但似乎无法让它发挥作用.我根据这些帖子在我的MVC5应用程序中创建了一个自定义的LifetimeManager for Unity: MVC3 Unity Framework and Per Session Lifetime Manager This may be the issue I am experiencing 这是
我已经阅读并使用Google搜索了所有内容,但似乎无法让它发挥作用.我根据这些帖子在我的MVC5应用程序中创建了一个自定义的LifetimeManager for Unity:
> MVC3 Unity Framework and Per Session Lifetime Manager 这是我的SessionLifetimeManager public class SessionLifetimeManager : LifetimeManager { private string key = Guid.NewGuid().ToString(); public override object GetValue() { return HttpContext.Current.Session[key]; } public override void RemoveValue() { HttpContext.Current.Session.Remove(key); } public override void SetValue(object newValue) { HttpContext.Current.Session[key] = newValue; } } 我只有几种我正在玩的类型,这是UnityConfig.cs中的相关注册: container.RegisterType<IEpiSession,EpiSession>(new SessionLifetimeManager(),new InjectionConstructor(config.AppServerURI,config.PathToSysConfig)); container.RegisterType<IReportRepository,EpicorReportRepository>(new TransientLifetimeManager()); DependencyResolver.SetResolver(new UnityDependencyResolver(container)); 请注意,EpicorReportRepository通过构造函数注入依赖于IEpiSession. public class EpicorReportRepository : IReportRepository { private IEpiSession session; // DI constructor public EpicorReportRepository(IEpiSession session) { this.session = session; } // ... } 我的问题:在第一个用户/会话连接到应用程序之后,之后的每个新用户/会话似乎仍在使用第一个用户为他创建/注入的EpiSession对象和凭据.这似乎是互联网上使用的常见模式,所以我想知道我错过了什么. 解决方法
你是如何测试IEpiSession在不同的会话中是否相同的?
尝试从不同的浏览器打开您的应用程序.如果在同一浏览器中打开多个选项卡,则使用相同的会话. 我检查了你的代码,它对我有用. DependencyResolver.SetResolver( type => container.Resolve(type),types => container.ResolveAll(types)); 完整的注册码如下: public class MvcApplication : System.Web.HttpApplication { protected void Application_Start() { ... var container = new UnityContainer(); container.RegisterType<IEpiSession,EpiSession>( new SessionLifetimeManager(),new InjectionConstructor("config.AppServerURI","config.PathToSysConfig")); container.RegisterType<IReportRepository,EpicorReportRepository>(new TransientLifetimeManager()); DependencyResolver.SetResolver( type => container.Resolve(type),types => container.ResolveAll(types)); } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net – 将Eval参数从ASPX文件传递给JavaScript函数
- asp.net – 获取隐藏字段的值
- asp.net-mvc – 动态URL路由ASP MVC
- .net – TagBuilder从MVC 3 beta版转到RC
- attributes – 利用属性版本控制在Swagger中利用MultipleAp
- asp.net-mvc – 在MVC 3 RC中实现TransferResult – 不起作
- ASP.net:我可以在bin文件夹中拥有2个不同版本的相同dll /
- asp.net-mvc – 用户经常注销(默认会员提供商)
- asp.net – IIS 7.5不加载静态html页面
- asp.net-mvc-3 – StructureMap初学者|物业注入
推荐文章
站长推荐
- asp.net-mvc – AspNet如何与我的模型识别
- asp.net – 如何绑定DropDownList的选定值
- asp.net – specflow的.msi安装程序和它的nuget包
- asp.net – $.post vs $.ajax
- asp.net – FormsAuthentication.SetAuthCookie(
- asp.net-mvc – 什么是实例化和配置DbContext在M
- asp.net – IIS 8.0中内核模式和用户模式缓存之间
- 在代理服务器后面设置ASP.NET应用程序的基本URL
- asp.net-mvc – ASP.Net MVC风格包不包括大多数文
- mvc项目架构分享系列之架构搭建之Repository和Se
热点阅读