I am trying to set an auth cookie in OnAuthorization of my custom attribute in asp.net mvc(C#) application.
when the session expires(New Session), i am setting an auth cookie again to make it available until the users logout.
I have used the following to set the auth cookie,
//set forms auth cookie
FormsAuthentication.SetAuthCookie(strUserName, true);
But when i check HttpContext.User.Identity.IsAuthenticated, it returns false.
How to set an auth cookie in OnAuthorization of custom attribute?
After setting the auth cookie, you won’t automatically get
Context.Userfilled in, you need to do something like:where strUserName must be non-null and not empty for
IsAuthenticatedto return true.On the next request,
Context.Usershould be set by theFormsAuthenticationModuleand you won’t have to do anything.