views:

1256

answers:

3

Hi I am trying to implement ASP.NET URL routing using the System.Web.Routing. And this seems to work fine on my localhost however when I go live I am getting an IIS 7's 404 error (File not found). FYI the hosting uses Windows Server 2008 IIS7.

I think this is making some difference in handling the routing mechanism. But I am not able to figure out whats exactly happening. Below are the settings and changes that I've made so far to get it work and to give some credit to myself it works absolutely fine locally.

Web.Config Settings

And then I have a system.webserver section that has the following markup

<system.webServer>
    <validation validateIntegratedModeConfiguration="false"/>
    <modules runAllManagedModulesForAllRequests="true">
      <remove name="Session" />
      <add name="Session" type="System.Web.SessionState.SessionStateModule"/>
      <add name="UrlRoutingModule"
               type="System.Web.Routing.UrlRoutingModule, 
                   System.Web.Routing, Version=3.5.0.0, 
                   Culture=neutral, 
                   PublicKeyToken=31BF3856AD364E35" />

    </modules>
    <handlers>
      <add name="UrlRoutingHandler" preCondition="integratedMode" verb="*" path="UrlRouting.axd" type="System.Web.HttpForbiddenHandler, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
    </handlers>   

</system.webServer>

Then in the Application_Start section I have defined one route as follows:

void Application_Start(object sender, EventArgs e) 
{
    RegisterRoutes(RouteTable.Routes); 
}
void RegisterRoutes(RouteCollection routes)
{               
    routes.Add(
       "MyRoute",
          new Route("ProductDetail/{ProductId}/{ProductName}",
                new MyRouteHandler("~/ProductDetail.aspx")));
}

Finally MyRouteHandler looks as follows:

 public IHttpHandler GetHttpHandler(RequestContext requestContext)
 {
     var display = (Page)BuildManager.CreateInstanceFromVirtualPath(
                     _virtualPath, typeof(Page));
     HttpContext.Current.Items["ProductId"] = requestContext.RouteData.Values["Product"]; 
     return display;
 }

And on the routed page I am grabbing the product ID as follows

ProductId = (int)HttpContext.Current.Items["Product"];

And this is the end of my mess. And this works fine locally. I have been trying this for a while but didn't succeeded so far.

ANY HELP WILL BE DEEPLY APPRECIATED.

Thanks...

A: 

I followed this article: How to: Use Routing with Web Forms

Before I found it I had issues on my shared host and none locally. It was my web.config.

My host was using IIS 7 with Integrated Pipeline, I was missing this:

<handlers>
    <!---after all the others--->    
    <add name="UrlRoutingHandler" preCondition="integratedMode" verb="*"
       path="UrlRouting.axd"
       type="System.Web.HttpForbiddenHandler,
       System.Web, Version=2.0.0.0,
       Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</handlers>

EDIT: According to your settings and code, the only thing left is to check to see if you have the Routing dll defined in web.config and also deployed to your bin directory:

<add assembly="System.Web.Routing, Version=3.5.0.0, 
  Culture=neutral, 
  PublicKeyToken=31BF3856AD364E35"/>
rick schott
Hi thanks for the response. Can you tell what changes you made to your web.config. That would be really helpful.
I added what fixed my problem. The article is very clear on how to set up Routing based on the host settings.
rick schott
Hi Thanks again for the reply. I have everything in the Web.Config and i have looked at the article you suggested. How ever I have all the necessary settings in Web.Config. I am really not able to figure out why its doing this. I dont know why IIS 7 is so complicated in getting simple things like this as URl routing or rewriting is very common these days.
A: 

I still don't have any solution.... I have the same problem.. I was moving a working website from 2003 to 2008 server from IIS6 to IIS7.. Even when I upload the code to the server, it is working locally but when I publish, it is not working by the server... I am getting "404 - File or directory not found."

Any suggestion:???

I have added this to my web.config, which was not there:


your response will be appreciated.

Isaac
+1  A: 

Just to inform what was finally my solution... on the IIS7 change the pipeline mode to Integrated and I folowed adding some lines on the web.config from the link above... http://msdn.microsoft.com/en-us/library/cc668202.aspx

good luck.

Isaac