简体   繁体   中英

URL Routing/ URL Rewriting on IIS 6 with ASP.NET 4? (Without IIS access)

I know this question has been asked alots of times and been asnwered alots of times also, but I ran into some really weird situaation as yesterday my code was working on both my Production Server and Development Machine but when I tried to run my site today, it was laughing on me with its 404s

I am stuck at Routing/ReWriting SEO Friendly URLs to my site's original pages, without being able to change anything at the IIS. First I tried to use UrlRewriter.NET, which worked on my Development Machine (Windows Server 2008, IIS 7) but didn't work on the staging server (Windows Server 2003 R2, IIS 6), as it threw a 404 error. Then I tried to use UrlRewriting.NET which also did the same as I remember.

EDIT: When I tried to use the UrlReWriting.NET they worked on my Visual Studio ASP.NET Development Server but not on IIS

Then a colleague of mine and a bit of searching convinced me to make use of Url Routing instead of URL ReWriting, so I got into ASP.NET Url Routing with the following code inside Global.asax

    protected void Application_Start(object sender, EventArgs e)
    {
        RegisterRoutes(RouteTable.Routes);
    }

    void RegisterRoutes(RouteCollection routes)
    {
        routes.MapPageRoute("GalleryCategory", "Gallery/", "~/Gallery.aspx");
        routes.MapPageRoute("Gallery", "Gallery/{*image}", "~/Gallery.aspx");
    }

And yes I also tried the solutions below in the web.config but of no use

    <modules runAllManagedModulesForAllRequests="true">
      <remove name="UrlRoutingModule"/>
      <add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
    </modules>

but they also left me in nowhere with all those 404s.

PS. I only have a single page on my site that needs to have SEO friendly URLs, the page name is Gallery.aspx and the PathInfo/QueryString Parameters are dynamic.

IMPORTANT: MY PRODUCTION SERVER IS WINDOWS SERVER 2003 WITH IIS 6 and MY DEVELOPMENT MACHINE IS WINDOWS SERVER 2008 IIS 7.

use this routing code in Global file, Application start, for the parameter: eg, www.domain.com/gallery/imgFile1/

void Application_Start(object sender, EventArgs e) 
{
    Routes.MapPageRoute("GalleryFile", "Gallery/{CatID}", "~/Gallery.aspx");
}

as for rewriting the Gallery Category page, put this code in Web.Config:

<system.web>
<urlMappings enabled="true">
<add url="~/Gallery/"  mappedUrl="~/Gallery.aspx" />
</urlMappings>
</system.web>

好吧,这听起来可能很疯狂,但是在所有这些搜索和拉长头发后,我试了一下,并确实重置了运行几乎30个网站的生产IIS(之所以我不愿意尝试任何疯狂的事情,包括IIS重置,但毕竟事实证明,仅使用命令iisreset重设IIS就可以解决问题。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM