asp.net 站点URLRewrite使用小记
更新时间:2009年11月30日 20:48:01 作者:
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");
}
}
}
中间有好多其它的流程就不标记了,这里只是列出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");
}
}
}
相关文章
asp.net core实现在线生成多个文件将多个文件打包为zip返回的操作
遇到安卓手机解压缩文件损坏问题时,可以考虑两种解决方案,方案一是使用SharpCompress库,它是一个开源项目,能够提供强大的压缩与解压功能,支持多种文件格式,方案二是采用aspose.zip库,这两种方法都能有效解决文件损坏的问题2024-11-11


最新评论