Authentication Mystery: When Membership.GetUser is null

When Membership.GetUser is null or nothing, but login succeeds (and fails on a bad password), check the path as such…

<authentication mode=”Forms” >
    <forms …
               path=”/” 
               …  >           
</authentication>

Mine was set to path =”blahblah/blah”.  I changed it to “/” and things worked again.

Has something to do with browsers rejecting the cookie because it didn’t look like it was coming from the right server.

One thought on “Authentication Mystery: When Membership.GetUser is null

  1. Also something to try is the following code:

    MembershipUser user = Membership.GetUser(username);
    GenericIdentity identity = new GenericIdentity(user.UserName);
    RolePrincipal principal = new RolePrincipal(identity);
    System.Threading.Thread.CurrentPrincipal = principal;
    HttpContext.Current.User = principal;