19

i am pretty new to MVC and Routing and i was asked to modify an app to use diffrent url's. a task that is a bit over me since i have no experience.

ok, lets talk a bit of code:

routes.MapRoute(
"CategoryBySeName", // Route name
"products/{SeName}", // URL with parameters
new { controller = "Catalog", action = "CategoryBySeName" }
);

this works as expected, but then the client wanted ".html" at the end of paths, so i changed:

"products/{SeName}", // URL with parameters

to:

"products/{SeName}.html", // URL with parameters

which fails ( IIS 404 page - MapRequestHandler) it seems like iis is trying to load a physical file with that name instead of passing it to the application.

Similar: ASP.NET MVC Routing to start at html page (not answered, Not duplicate)

Community
  • 1
  • 1
Rafael Herscovici
  • 16,558
  • 19
  • 65
  • 93
  • 1
    Plug the route debugger in and see what's really happening. http://haacked.com/archive/2008/03/13/url-routing-debugger.aspx – 3Dave Feb 17 '12 at 16:28

4 Answers4

10

You have to force all request through the ASP.NET pipeline, and you can do that by adding only this single line to the web.config of your application:

<system.webServer>
  <modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
György Balássy
  • 2,938
  • 1
  • 28
  • 23
9

You're guess that an IIS handler is probably grabbing the request prior to MVC is likely correct.

Assuming IIS 7: http://technet.microsoft.com/en-us/library/cc770990(v=ws.10).aspx

You need to edit the .html handler in IIS to use ASP.NET.

You can find it in the website properties under the home directory tab in app configuration in the mappings section in II6.

Something along the lines of (version may be different): C:\windows\microsoft.net\framework\v4.0.30319\aspnet_isapi.dll is what you need to handle the .html files.

Joshua Enfield
  • 17,642
  • 10
  • 51
  • 98
  • 2
    `` added this to my web.config, the problem still exists. – Rafael Herscovici Feb 17 '12 at 16:11
  • I'm not sure on the possibility of doing this without IIS access. My understanding (which may be incorrect) is that IIS determines where to send the request based on the mappings, and the handlers are not able to override other handlers in normal circumstances. – Joshua Enfield Feb 17 '12 at 16:16
  • 5
    for anyone that needs to fix this in IIS Express too when debugging, find the IIS Express icon in system tray, "Show all applications", select your app and click the link to the configuration source, then add a line for "\*.html" mirroring all the "\*.cshtml" lines in the location/system.webServer/handlers nodes at the bottom. – Tom Carver Jul 19 '12 at 12:03
3

Just add this section to Web.config, and all requests to the route/{*pathInfo} will be handled by the specified handler, even when there are dots in pathInfo. (taken from ServiceStack MVC Host Web.config example and this answer https://stackoverflow.com/a/12151501/801189)

  <location path="route">
    <system.web>
      <httpHandlers>
        <add path="*" type="System.Web.Handlers.TransferRequestHandler" verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" />
      </httpHandlers>
    </system.web>
    <!-- Required for IIS 7.0 -->
    <system.webServer>
      <modules runAllManagedModulesForAllRequests="true" />
      <validation validateIntegratedModeConfiguration="false" />
      <handlers>
        <add name="ApiURIs-ISAPI-Integrated-4.0" path="*" type="System.Web.Handlers.TransferRequestHandler" verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" preCondition="integratedMode,runtimeVersionv4.0" />
      </handlers>
    </system.webServer>
  </location>
Community
  • 1
  • 1
V.B.
  • 6,236
  • 1
  • 33
  • 56
3

Changing the Application Pool from Classic to Integrated fixed the issue. thank you guyz for your help.

Rafael Herscovici
  • 16,558
  • 19
  • 65
  • 93