我正在使用Microsoft.ASPNET.Identity提供程序,我想設置自定義主體。此前有FomrsAuthentication爲ASP.NET身份提供商設置自定義主體
,我會做這樣的事情:
protected void Application_AuthenticateRequest(Object sender, EventArgs e)
{
HttpCookie authCookie = Request.Cookies[FormsAuthentication.FormsCookieName];
if(authCookie != null)
{
using (var db = new GSCM.Logic.GSCMDatabase())
{
FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(authCookie.Value);
var id = new GenericIdentity(ticket.Name);
var principal = new VmUserLogin(id);
var found = db.LoadInternalUser(ticket.Name);
if(found != null)
{
Mapper.Map(found, principal);
}
HttpContext.Current.User = principal;
}
}
}
我可怎麼辦與ientity提供商
爲什麼您需要要做到這一點? –
所以我有權訪問每個控制器動作中的對象,而不必每次都加載它 – dagda1