2010-04-26 134 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