Question

I'm seeing a strange behavior in our .NET web application. It occurs very rarely, but if I sit on a page and keep hitting F5, eventually I will have Membership.GetUser() return NULL even though Request.IsAuthenticated is returning true.

if (Request.IsAuthenticated)
{
    MembershipUser user = Membership.GetUser(); //user is occasionally null.
}

My understanding is that this shouldn't happen and the intermittent nature of the problem makes me think this is a bug, but aside from putting the GetUser() call in a WHILE loop (which eliminates the issue as GetUser() works on the second try), I'm not sure where else to look for what is causing this. We are using a web service on another server as our membership provider, but I've eliminated this as a timeout issue, which returns a different error.

Was it helpful?

Solution

Membership and Authentication have nothing to do with each other (well, almost nothing). Request.IsAuthenticated merely means that there is a valid FormsAuthentication cookie on the browsers computer. It has nothing to do with getting the Membership information, other than by providing the correct IIdentity.Name value.

It seems likely that the issue here is in your Membership provider. You mention that you use a web service to retrieve membership information. You say that you've eliminated that as a source of the problem, but don't say how you've eliminated it.

I would say it's highly likely related to this webservice.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top