开发者

Storing user state in session

开发者 https://www.devze.com 2023-02-27 03:01 出处:网络
Excuse the extremely newbie question... Once I 开发者_如何学运维have verified the users login credentials, Where should I store the state for whether a user is logged in or not?Once you have validate

Excuse the extremely newbie question...

Once I 开发者_如何学运维have verified the users login credentials, Where should I store the state for whether a user is logged in or not?


Once you have validated that your user is OK according to the backend, you can make ASP.NET set an authentication cookie for the user in the response by doing a FormsAuthentication.SetAuthCookie(username, persistent).

From then on, ASP.NET will decrypt that cookie in requests and extract the username from it, giving you access to it via HttpContext.Current.User.

To me, it sound like this is what you're looking for.


You don't normally need to store this state yourself. If you are using one of ASP.NET's built in authentication mechanisms (e.g. Form Auth) you can simply check: Request.IsAuthenticated

0

精彩评论

暂无评论...
验证码 换一张
取 消