6
我想知道什麼最好的方法是用我自己的CustomGenericPrincipal替換genericPrincipal。Asp.net:替換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接口主要來取代它,因爲我在做與Ninject如下:
Bind<ICustomPrincipal>().ToMethod(x => (ICustomPrincipal)HttpContext.Current.User)
.InRequestScope();
那麼什麼是更換的GenericPrincipal的最佳方式?
由於提前,
Pickels
感謝您的答案和額外的提示。 – Pickels 2010-05-05 11:42:19