惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
F
Fortinet All Blogs
量子位
G
Google Developers Blog
J
Java Code Geeks
N
Netflix TechBlog - Medium
博客园 - 聂微东
宝玉的分享
宝玉的分享
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
月光博客
月光博客
The Cloudflare Blog
Apple Machine Learning Research
Apple Machine Learning Research
爱范儿
爱范儿
雷峰网
雷峰网
M
MIT News - Artificial intelligence
T
Tailwind CSS Blog
V
Visual Studio Blog
阮一峰的网络日志
阮一峰的网络日志
博客园 - 三生石上(FineUI控件)
Microsoft Azure Blog
Microsoft Azure Blog
aimingoo的专栏
aimingoo的专栏
Martin Fowler
Martin Fowler
有赞技术团队
有赞技术团队
T
The Blog of Author Tim Ferriss

博客园 - 疾风

Internet Explorer允许的URL最大长度为2083个字符(Maximum URL length is 2,083 characters in Internet Explorer) Eval和Bind 古筝和古琴有什么区别? 认识CSS中absolute与relative BAT详细手册 iframe的使用 领域逻辑的实现分类 面向对象问答 用户点击Log In按钮后发生了什么?(续篇1) 微软的在线RSS阅读器 2003年至2006年项目总结 经常会有一些Gmail的邀请函 Visual Studio 2005 RTM的奇怪问题 在.Net代码中验证XML文档 2006年的一些目标 创建强类型的程序集 在.net中使用强类型来读取配置信息 自己做了一个单元测试的小工具---EasyTest.net How to gets the path for the executable file?
用户点击Log In按钮后发生了什么?
疾风 · 2006-06-08 · via 博客园 - 疾风

    Asp.net2.0提供了一系列登录相关组件,其中的Login控件使用起来可谓是简单之至,只需要在Login控件的Authenticate事件处理方法中验证用户输入的帐号、密码的正确性,然后把其中AuthenticateEventArgs类型的参数的Authenticated属性改成true就算用户登录成功了:

1 protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
2 {
3     if (UserIsValid(Login1.UserName, Login1.Password))
4     {
5         e.Authenticated = true;
6     }
7 }

    嗯,用户点击“Log In”按钮后发生了什么?凭什么Asp.net运行环境就相信用户已经登录成功,在以后的请求中不会中途调转到“登录”界面?我们就来看看吧。
    用Lutz Roeder's .NET Reflector打开System.Web.dll程序集,在System.Web.UI.WebControls名称空间里Login类的AttemptLogin方法中,你看到了什么?

 1 private void AttemptLogin()
 2 {
 3 
 4             LoginCancelEventArgs args1 = new LoginCancelEventArgs();
 5             this.OnLoggingIn(args1);
 6             if (!args1.Cancel)
 7             {
 8                   AuthenticateEventArgs args2 = new AuthenticateEventArgs();
 9                   this.OnAuthenticate(args2);//这里将执行我们的Login1_Authenticate方法
10                   if (args2.Authenticated)
11                   {
12                         //嘿,只是设置了一下AuthCookie而已
13                         FormsAuthentication.SetAuthCookie(this.UserNameInternal, this.RememberMeSet);
14                         this.OnLoggedIn(EventArgs.Empty);
15                         this.Page.Response.Redirect(this.GetRedirectUrl(), false);
16                   }
17 
18             }
19       }
20 }

    真的很简单。