当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > asp.net 站点URLRewrite使用小记

ASP.NET
细细品味ASP.NET(一)
细细品味ASP.NET(二)
细细品味ASP.NET(三)
细细品味ASP.NET(四)
细细品味ASP.NET(五)
用asp.net和xml做的新闻更新系统(1)
用asp.net和xml做的新闻更新系统(2)
用asp.net和xml做的新闻更新系统(3)
十天学会ASP.net(1)
十天学会ASP.net(2)
十天学会ASP.net(3)
十天学会ASP.net(4)
十天学会ASP.net(5)
十天学会ASP.net(6)
十天学会ASP.net(7)
十天学会ASP.net(8)
十天学会ASP.net(9)
十天学会ASP.net(10)
ASP.NET创建XML Web服务全接触(1)
ASP.NET创建XML Web服务全接触(2)

ASP.NET 中的 asp.net 站点URLRewrite使用小记


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2010-01-10   浏览: 136 ::
收藏到网摘: n/a

asp.net的底层运作已经也乱谈过一番, 今天记一下URLRewrite的方法。 IIS收到请求-->ISAPI用于处理该请求-->BeginRequest开始-->EndRequest结束-->输出Response
中间有好多其它的流程就不标记了,这里只是列出URLRewrite所走的流程。
其实就是在BeginRequest事件中调用HttpContext的RewritePath方法,将该请求重新“定位”至一个目标URL就完成了。
在站点的Global.asax文件BeginRequest方法中添加代码:
复制代码 代码如下:

public class Global : System.Web.HttpApplication
{
protected void Application_BeginRequest(object sender, EventArgs e)
{
HttpContext context = HttpContext.Current;
if (context.Request.Path.Equals("/demo", StringComparison.InvariantCultureIgnoreCase))
{
context.RewritePath("~/demoList.aspx");
}
}
}