欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

asp.net 站点URLRewrite使用小记

程序员文章站 2024-03-08 16:59:28
iis收到请求-->isapi用于处理该请求-->beginrequest开始-->endrequest结束-->输出response 中间有好多其...
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");
}
}
}