Can you tell me why FormsAuthentication.SetAuthCookie(user.Name, false);
is not causing Request.IsAuthenticated
to be true?
Here is my code
In my case, it was a problem in Chrome browser. I just removed all cookies stored and works.
I had exactly same problem in my MVC4 Web Application
. One more possible reason for this problem is below method in IdentityModels.cs
file
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
{
// Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
// Add custom user claims here
return userIdentity;
}
Make sure DefaultAuthenticationTypes
is ApplicationCookie
Cheers,
I had the same problem in an MVC5 project. The solution was to add the following lines to the modules section in the system.webServer
<remove name="FormsAuthentication" />
<add name="FormsAuthentication" type="System.Web.Security.FormsAuthenticationModule" />
In my case I had this issue which ended up in a redirect-loop where the user would be redirected to the login, successfully logged in and then back to our site but since Request.IsAuthenticated was false the user was redirected to the login agan.
In our case this was solved by using another CookieManager,
var cookieOptions = new CookieAuthenticationOptions();
cookieOptions.CookieManager = new SystemWebCookieManager();
app.UseCookieAuthentication(cookieOptions);
Turns out that there was some kind of bug in Katana that this other CookieManager worked around, in out case this solved the issue.
https://github.com/aspnet/AspNetKatana/wiki/System.Web-response-cookie-integration-issues