且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

ASP.NET 4.0 URL 路由 HTTP 错误 404.0 - 未找到

更新时间:2022-01-24 10:46:13

使用 IIS 7.5 启用默认的 ASP.Net 4.0 路由:

To enable default ASP.Net 4.0 routing with IIS 7.5:

  1. 确保您已安装HTTP 重定向功能可以这样做 -> 控制面板 -> 程序 -> 关闭 Windows 功能 -> 万维网服务 -> 常用 HTTP 功能 -> HTTP 重定向
  2. 使用以下代码修改您的 web.config
  1. Make sure that you have installed the HTTP Redirection feature It can be done -> Control Panel -> Progams -> Turn off windows features -> World wide web Services -> Common HTTP Features -> HTTP Redirection
  2. Modify your web.config with the code below

 

<system.webServer>   
    <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>
    <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>

3.在 global.asax 文件中创建路由

3. Create Routes in your global.asax file

注意:您必须将应用程序池设置为 Asp.net 4.0 应用程序池,因为路由不适用于 Asp.net 4.0 经典应用程序池.

Note: You have to set Application Pool to Asp.net 4.0 application pool , as routing is not working with Asp.net 4.0 Classic Application pool.

希望这会有所帮助.