【发布时间】:2011-02-15 14:14:09
【问题描述】:
我想知道用我自己的 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 的最佳方法是什么?
提前致谢,
泡菜
【问题讨论】:
标签: asp.net asp.net-mvc security asp.net-membership