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

推荐订阅源

人人都是产品经理
人人都是产品经理
Google DeepMind News
Google DeepMind News
博客园 - 【当耐特】
量子位
博客园 - 司徒正美
爱范儿
爱范儿
Hugging Face - Blog
Hugging Face - Blog
博客园 - 聂微东
Jina AI
Jina AI
J
Java Code Geeks
腾讯CDC
大猫的无限游戏
大猫的无限游戏
V
Visual Studio Blog
I
InfoQ
D
Docker
Recent Announcements
Recent Announcements
MongoDB | Blog
MongoDB | Blog
博客园 - Franky
宝玉的分享
宝玉的分享
G
Google Developers Blog
GbyAI
GbyAI
Y
Y Combinator Blog
有赞技术团队
有赞技术团队
H
Help Net Security

博客园 - 融化了的朱古力

AJAX Automated Testing Object design Online dictionary ASP.NET 2.0服务器控件与组件开发高级编程 Professional asp.net 2.0 Server Control and Component Development .NET组件程序设计 .NET组件程序设计0723 .NET组件程序设计0721 .NET组件程序设计 never draw to an inside straight Per say Agile Principles, Patterns, and Practices in C# MapControl MapPoint Helpful Links 20060827 20060812 what is locality of reference? 20060806 20060802
Professional asp.net 2.0 server control and component dev...
融化了的朱古力 · 2007-10-10 · via 博客园 - 融化了的朱古力

P653 Listing 21-21

void OnLogin(object sender, EventArgs e)
{
if (CustomComponents.Membership.ValidateUser(userNameTextBox.Text,
passwordTextBox.Text))
{
FormsAuthenticationTicket ticket 
= new FormsAuthenticationTicket( 1,
userNameTextBox.Text, DateTime.Now,
DateTime.Now.AddSeconds(
40),falsestring.Empty);
string encryptedTicket = FormsAuthentication.Encrypt(ticket);
HttpCookie cookie 
= new HttpCookie(FormsAuthentication.FormsCookieName);
cookie.Value 
= encryptedTicket;
Page.Response.Cookies.Add(cookie);
EnsureChildControls();
Page.Response.Redirect(
FormsAuthentication.GetRedirectUrl(userNameTextBox.Text, 
false), true);
}

}

对于EnsureChildControls()的调用,作者解释:

The OnLogin method calls the EnsureChildControls method before the call into the Redirect method because it passes the value of the Text property of the username TextBox into the Redirect method. Recall that every composite
control must call the EnsureChildControls method before it attempts to access its child controls:

但是之前的代码早已经access its child controls了。奇怪。

if (CustomComponents.Membership.ValidateUser(userNameTextBox.Text,
passwordTextBox.Text))