Asp.net:替换GenericPrincipal
发布时间:2020-12-16 03:53:40 所属栏目:asp.Net 来源:网络整理
导读:我想知道用我自己的CustomGenericPrincipal替换genericPrincipal最好的方法是什么. 目前我有这样的事情,但我不确定它是否正确. protected void Application_AuthenticateRequest(Object sender,EventArgs e){ HttpCookie authCookie = Request.Cookies[Forms
我想知道用我自己的CustomGenericPrincipal替换genericPrincipal最好的方法是什么.
目前我有这样的事情,但我不确定它是否正确. protected void Application_AuthenticateRequest(Object sender,EventArgs e) { HttpCookie authCookie = Request.Cookies[FormsAuthentication.FormsCookieName]; if (authCookie != null) { FormsAuthenticationTicket authTicket = FormsAuthentication.Decrypt(authCookie.Value); var identity = new CustomIdentity(authTicket); var principal = new CustomPrincipal(identity); Context.User = principal; } else { //Todo: check if this is correct var genericIdentity = new CustomGenericIdentity(); Context.User = new CustomPrincipal(genericIdentity); } } 我需要替换它,因为我需要一个实现我的ICustomPrincipal接口的Principal,因为我正在使用Ninject执行以下操作: Bind<ICustomPrincipal>().ToMethod(x => (ICustomPrincipal)HttpContext.Current.User) .InRequestScope(); 那么替换GenericPrincipal的最佳方法是什么? 提前致谢, Pickels 解决方法
你错过了一个微妙的细节,线程.
Context.User = Thread.CurrentPrincipal = new CustomPrincipal.... 将带你到你需要去的地方. 另外我注意到你提到你只需要替换校长.如果是这种情况,您可以简单地重用已经为您构造的FormsIdentity,如下所示. Context.User = Thread.CurrentPrincipal = new CustomPrincipal(Context.User.Identity /*,add roles here if desired*/ ); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-mvc – 将HttpContext.Current.User.Identity传递给
- asp.net-mvc – 具有Windows身份验证的MVC3 Web应用程序中的
- 将列表绑定到asp.net 3.5中的列表视图
- asp.net-mvc – 如何测试Asp.Net MVC视图是否无异常呈现?
- asp.net – jqGrid – 如何计算列到jqgrid?
- asp.net – 我应该花费我的努力实现knockoutjs或查看jQuery
- asp.net-mvc – 有没有办法为MVC控制器中的每个动作设置[Au
- asp.net – Webservices可以作为单身人士引起不同用户的问题
- asp.net-mvc-4 – 为什么ResolveBundleUrl不能用于自定义文
- asp.net-web-api – Autofac,Owin,Webapi并注入Authorizati
推荐文章
站长推荐
- adfs2.0 – 启用了非声明的ASP.NET应用程序和ADF
- 在asp.net中读取查询字符串而不指定任何页面名称
- asp.net – 如何摆脱包含GridView的空div
- asp.net-mvc – ASP.NET MVC中依赖于语言的路由
- asp.net-mvc – 如何在MVC Razor视图中查找编译时
- 如何从ASP.Net MVC中的JavaScript到TypeScript?
- asp.net-mvc – 在ASP.net MVC单元测试中访问Mod
- asp.net-mvc – WebApi(ApiController)与ASP.Net
- C#获取某一路径下的所有文件名信息(包括子文件夹
- asp.net-mvc-3 – 如何在mvc3视图中的mvcgrid中多
热点阅读