asp.net MVC 4 アプリケーションで FormsAuthentication を使用しようとしています。認証自体は正常に機能しますが、FormsAuthenticationEventArgs.User からユーザーを取得して Http.Context.Current.User に割り当てるときはいつでも、まさにその瞬間に機能し、次の呼び出しメソッド Http.Context.Current.User は再び null になります...私は何を間違っていますか?
protected void FormsAuthentication_OnAuthenticate(Object sender, FormsAuthenticationEventArgs e)
{
if (FormsAuthentication.CookiesSupported == true)
{
if (Request.Cookies[FormsAuthentication.FormsCookieName] != null)
{
try
{
string username = FormsAuthentication.Decrypt(Request.Cookies[FormsAuthentication.FormsCookieName].Value).Name;
var usuarioRn = new UsuarioRN();
string roles = usuarioRn.GetRoles(username);
FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(Request.Cookies[FormsAuthentication.FormsCookieName].Value);
e.User = new System.Security.Principal.GenericPrincipal(new System.Web.Security.FormsIdentity(ticket), roles.Split(';'));
//First time get here assign e.User to HttpContext.Current.User, all good
//Next call HttpContext.Current.User is again null, why?
HttpContext.Current.User = e.User;
}
catch (Exception)
{
}
}
}