Pregunta

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.

¿Fue útil?

Solución

use this routing code in Global file, Application start, for the parameter: e.g, 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>

Otros consejos

Well it might sound crazy but after all these searching and pulling my hair literally I gave it a shot and I did reset my production IIS which is running almost 30 Websites (the reason I was reluctant to try anything crazy including the IIS reset but after all it turns out that just resetting the IIS did the trick using the command iisreset

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top