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)

1

4 Answers 4

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>
Sign up to request clarification or add additional context in comments.

2 Comments

This worked for my ASP.Net MVC 4 application running in IIS Express
this works for me as well, with this path products/{SeName}. no need to add .html at the end of path
8

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.

3 Comments

<staticContent><remove fileExtension=".html" /></staticContent> added this to my web.config, the problem still exists.
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.
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.
3

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

Comments

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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.