In my MasterPage code-behind I try to get UserID of the authenticated (if it has) one:
public Guid CurrentUserID
{
get
{
Guid userID = new Guid();
if (Context.User.Identity.IsAuthenticated)
{
MembershipUser user = Membership.GetUser(Context.User.Identity.Name);
userID = (Guid)user.ProviderUserKey;
}
return userID;
}
}
Once the error "Object reference not set to an instance of an object" appeared. I suspect the problem is in the case Context.User=null. Could it be the reason?