ASP.NET, IIS 6 and url rewriting

2019-07-25 10:05发布

问题:

i've bought a shared hosting on a windows hoster with IIS 6.

I would like to know how to rewrite url.

I can't modify anything on the server, the only thing i can do is to use ... my asp.net code ! some advice ?

Thanks!

回答1:

As the ScottGu blog suggests, you can

1. Do the rewrite manually using the HttpContext.RewritePath() method that ASP.NET provides

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. Use a HttpModule
Using a HttpModule (such as urlrewriter.net) does not require any changes on the server, only some changes on Web.Config and deploying the module DLLs