1
这里了登录操作:不能办理会员用户名根据登录行动
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)
当我尝试调试变量,它说,“NullReferenceException异常,未将对象引用设置到对象的实例。 “
这只是一分钟前的工作!我怎样才能获得用户名变量?谢谢。
这工作,并很好的建议。然而,我很好奇,为什么它工作之前,突然停止...我使用Membership.GetUser.UserName,它给我的用户名! – user1477388 2012-08-03 18:28:42
Cookie可能已经被发送,但随后被清除或更改? – Dan 2012-08-03 18:31:37
我认为这是可能的,但我不确定。谢谢你的帮助,丹。 – user1477388 2012-08-03 18:37:09