2010-04-26 135 views
1

我已經購買了與IIS 6的Windows主機共享主機。ASP.NET,IIS 6和URL重寫

我想知道如何重寫url。

我不能修改服務器上的任何東西,我唯一能做的就是使用...我的asp.net代碼! 有些建議?

謝謝!

+2

看看:http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx – Steve 2010-04-26 16:50:44

+0

謝謝,但我已經已經看過那篇文章,但我找不到iis 6的解決方案! :( – stighy 2010-04-26 21:16:50

回答

1

正如ScottGu博客暗示,你可以

1.執行重寫使用HttpContext.RewritePath()方法ASP.NET提供

void Application_BeginRequest(object sender, EventArgs e) { 

    string fullOrigionalpath = Request.Url.ToString(); 

    if (fullOrigionalpath.Contains("/Products/Books.aspx")) { 
     Context.RewritePath("/Products.aspx?Category=Books"); 
    } 
    else if (fullOrigionalpath.Contains("/Products/DVDs.aspx")) { 
     Context.RewritePath("/Products.aspx?Category=DVDs"); 
    } 
} 

2.使用HTTP模塊
使用手動HttpModule(如urlrewriter.net)不需要對服務器進行任何更改,只需對Web.Config進行一些更改並部署模塊DLL