ASP.NET MVC Routing - add .html extension to routes

前端 未结 4 658
别那么骄傲
别那么骄傲 2020-11-28 12:56

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

相关标签:
4条回答
  • 2020-11-28 13:13

    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>
    
    0 讨论(0)
  • 2020-11-28 13:14

    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>
    
    0 讨论(0)
  • 2020-11-28 13:17

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

    0 讨论(0)
  • 2020-11-28 13:26

    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.

    0 讨论(0)
提交回复
热议问题