目前我的產品頁面的網址是像URL重寫+會話和應用程序變量定義HTTP處理程序
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和所有其他模塊和處理程序運行。你爲什麼不使用路線? – user3285954