MVC 4 SimpleMembership - Why WebSecurity.CurrentUserId -1 after login

后端 未结 1 953
太阳男子
太阳男子 2020-12-03 22:18

I am trying to set a cookie upon login and having issues with getting the current user id after login. In the below, intUserId is -1 and WebSecurity.IsAuthenticated is false

相关标签:
1条回答
  • 2020-12-03 22:56

    Login only sets the Forms Authentication cookie.

    The way asp.net authentication works is that it must read the cookie to set the authenticate the request, but since the cookie did not exist when the Login page was started, the framework doesn't know anything about the user.

    Reload the page, and you will find the information is available.

    FYI, this is nothing new with SimpleMembership or WebSecurity, this is the way Forms Authentication has always worked.

    0 讨论(0)
提交回复
热议问题