Global/重写向/Render/目录详解

来源:互联网 发布:苹果笔记本mac系统升级 编辑:程序博客网 时间:2024/05/06 11:39

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);//内部重定向,保存参数

            }

目录详解

Mycss.css
nav{background-image:url(****/*.*)}  //相对于css文件的当前位置搜索图片
nav{background-image:url(/****/*.*)} //相对于网站的根目录位置搜索图片

~/web/index.aspx  打开b.jpe文件
~/web/a/b.jpe
~/a.jpe

相对URL 难以移动文件。移动到另一个目录就可能断开。

a/b.jpe     相对于index.aspx文件的当前位置搜索jpe图片      ~/web/a/b.jpe
../a.jpe     相对于index.aspx文件的上一级位置搜索a.jpe图片  ~/a.jpe
../.. 上一级的上一级目录 

基于根目录的相对URL

/web/a/b.jpe     相对根目录搜索b.jpe图片      ~/web/a/b.jpe

服务端的相对URL(虚拟路径/“虚拟应用程序”路径)必须为 runat="server"控件

~/web/a/b.jpe 服务端的相对(URL虚拟路径)以虚拟应用程序目录为~后接网站目录

绝对URL 如果引用自己站点之外的资源就必须用绝对URL

http://www.163.com/index.html
http://127.0.0.1/web/a/b.jpe

 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());

        }  

0 0
原创粉丝点击