MVC 4个简单的会员资格。有人如何检查登录或不 [英] MVC 4 simple membership. How to check is somebody logged in or not
问题描述
我在MVC 4新的无法理解的成员究竟是如何工作的简单。所有配置后,我把这个code到的AccountController,看看它是如何工作的,并且它在所有的工作。
I'm new in mvc 4 and can't understand exactly how simple membership worked. After all configuration I put this code to AccountController to see how it works and is it work at all
string UserName1 = WebSecurity.CurrentUserName;
bool LoginResult= WebSecurity.Login("admin", "111111");
string UserName2 = WebSecurity.CurrentUserName;
WebSecurity.Logout();
当我运行调试我看到,毕竟成品
And when I run debugger I see that after all finished
UserName1 = ""
LoginResult = true
UserName2 = ""
一切都只是而UserName2确定。为什么是空的?登录是sussess ...
我也看不到用户名在WebSecurity和WebSecurity.IsAuthentificated是假的
为什么登录成功,但WebSecurity并不说明它呢?
Everything is ok except UserName2. Why it is empty? Login was sussess... Also I can't see UserID at WebSecurity and WebSecurity.IsAuthentificated is false Why login was successful but WebSecurity do not shows it at all?
推荐答案
登录不会做你认为它。它不会立即设置当前用户,而是设置在用户的Web浏览器的cookie,并在接下来的页面刷新,asp.net将认识到Cookie,并给他们一个身份验证的要求。
Login does not do what you think it does. It does not immediately set the current user, instead it sets a cookie on the users web browser, and on the next page refresh, asp.net will recognize that cookie and give them an authenticated request.
这是不特定于简单的会员,这是所有认证在asp.net中是如何工作的。一旦通过验证,该页面已被刷新为被认可登录。
This is not specific to simple membership, that's how all authentication works in asp.net. Once authenticated, the page has to be refreshed for a login to be recognized.
这篇关于MVC 4个简单的会员资格。有人如何检查登录或不的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!