Here is my LogOn Action:
Public Function LogOn(ByVal model As LogOnModel, ByVal returnUrl As String) As ActionResult
If ModelState.IsValid Then
If Membership.ValidateUser(model.UserName, model.Password) Then
FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe)
If Url.IsLocalUrl(returnUrl) AndAlso returnUrl.Length > 1 AndAlso returnUrl.StartsWith("/") _
AndAlso Not returnUrl.StartsWith("//") AndAlso Not returnUrl.StartsWith("/\\") Then
Return Redirect(returnUrl)
Else
' redirect based on whether the user is admin, company owner, or blog owner
Debug.Print(Membership.GetUser.UserName)
When I try to debug the variable, it says, “NullReferenceException, Object reference not set to an instance of an object.”
It was just working a minute ago! How can I get the username variable? Thanks.
Setting the authentication cookie adds it to the response of the current request. The cookie is not yet present in the request until after the response is sent to the client, and the client sends it in subsequent requests.
The good news is that you already have the username from the model so I would suggest using that.