Global
Application_Start //请求开始
Application_End //请求结束
Application_Error//请求错误
Application_BeginRequest//开始请求页面
Application_EndRequest//结束请求页面
Application_AuthenticateRequest
Session_Start//Session开始表示一个新用户连接 Session.Timeout=10;
Session_End//Session结束表示一个用户注销
重写向
Uriui=HttpContext.Current.Request.Url;//Context.Request.AppRelativeCurrentExecutionFilePath
Regexrg=newRegex(@"view(\d+)\.aspx");
Matchmt=rg.Match(Context.Request.Url.AbsolutePath);
if (mt.Success)
{
stringid=mt.Groups[1].Value;
Context.RewritePath(@"~\WebForm2.aspx?id="+id);//在Global
中改变请求的Url,在Load中已经不能改变请求的Url PreInit不知道行不行
Context.Response.Redirect(@"~\WebForm2.aspx?id="+id);//页面重定向,从新请求
Context.Server.Transfer(@"~\WebForm2.aspx?id="+id,true);//内部重定向,保存参数
}
目录详解
相对URL 难以移动文件。移动到另一个目录就可能断开。
基于根目录的相对URL
服务端的相对URL(虚拟路径/“虚拟应用程序”路径)必须为 runat="server"控件
绝对URL 如果引用自己站点之外的资源就必须用绝对URL
Render
protected override void Render(HtmlTextWriterwriter)
{
System.IO.StringWriterhtml=newSystem.IO.StringWriter();
System.Web.UI.HtmlTextWritertw=newSystem.Web.UI.HtmlTextWriter(html);
base.Render(tw);
Html=html.ToString();
tw.Close();
Response.Write(html.ToString());
}