【发布时间】:2012-10-05 11:11:22
【问题描述】:
目前我的产品页面网址是这样的
http://www.localhost:80/products/default.aspx?code=productCode
我想访问产品页面
http://www.localhost:80/productCode
我为此使用了 HTTP 模块。
public class UrlRewritingModule : IHttpModule
{
public void Dispose()
{
}
public void Init(HttpApplication context)
{
context.PreRequestHandlerExecute += new EventHandler(context_PreRequestHandlerExecute);
context.AuthorizeRequest += new EventHandler(context_AuthorizeRequest);
}
void context_AuthorizeRequest(object sender, EventArgs e)
{
HttpContext context = ((HttpApplication)sender).Context;
if (some condition)
{
context.RewritePath(url);
}
}
void context_PreRequestHandlerExecute(object sender, EventArgs e)
{
//We set back the original url on browser
HttpContext context = ((HttpApplication)sender).Context;
if (context.Items["originalUrl"] != null)
{
context.RewritePath((string)context.Items["originalUrl"]);
}
}
}
我已经在 web.config 中注册了它,它工作正常。但是当我在 IIS 中部署它时,会话和应用程序变量不会抛出空引用异常。
谁能帮帮我?
编辑:是否需要额外的代码来访问会话/应用程序变量以重写 URL ?
【问题讨论】:
标签: asp.net url-rewriting httpmodule vanity-url