2011-04-15 127 views
8

我已經在ASP.NET應用程序中創建了路由規則,並且在IIS7上的開發機器上一切正常。當我將解決方案部署到也有IIS7的prod服務器時,在訪問URL時出現錯誤404(找不到頁面)。也許有人可以指出問題在哪裏?路由HTTP錯誤404.0 0x80070002

實際的錯誤

HTTP錯誤404.0 - 未找到您正在尋找的 資源已經 刪除,更名,或 暫時不可用。詳細 錯誤InformationModule IIS Web核心 通知MapRequestHandler 處理程序StaticFile錯誤代碼 0x80070002請求的URL http://xxx.xxx.xxx.xxx:80/pdf-button 物理路徑 C:\ WWW \ pathtoproject \ PDF按鈕登錄 方法匿名登錄用戶匿名

我的實際代碼

 <add key="RoutePages" value="all,-forum/"/> 

      UrlRewrite.Init(ConfigurationManager.AppSettings["RoutePages"]); 


    public static class UrlRewrite 
    { 
      public static void Init(string routePages) 
      { 

       _routePages = routePages.ToLower().Split(new[] { ',' }); 
       RegisterRoute(RouteTable.Routes); 




      } 

      static void RegisterRoute(RouteCollection routes) 
      { 

       routes.Ignore("{resource}.axd/{*pathInfo}"); 
       routes.Ignore("favicon.ico"); 
       foreach (string routePages in _routePages) 
       { 
        if (routePages == "all") 
         routes.MapPageRoute(routePages, "{filename}", "~/{filename}.aspx"); 
        else 
         if (routePages.StartsWith("-")) 
          routes.Ignore(routePages.Replace("-", "")); 
         else 
         { 
          var routePagesNoExt = routePages.Replace(".aspx", ""); 
          routes.MapPageRoute(routePagesNoExt, routePagesNoExt, string.Format("~/{0}.aspx", routePagesNoExt)); 
         } 
       } 

      } 
} 
+0

你使用什麼類型的路由? MVC? – 2011-04-15 13:02:13

+0

我用System.Web.Routing.RouteCollection類(.NET 4.0) – Tomas 2011-04-15 13:04:09

+0

什麼是你希望它被路由到 - PDF-button.aspx?正如我敢肯定你已經意識到0x80070002 = ERROR_FILE_NOT_FOUND – Rup 2011-04-15 13:39:04

回答

23

剛剛發現下面的行必須添加到web.config文件,現在一切工作正常在Prod服務器上也是如此。

<system.webServer> 
    <modules runAllManagedModulesForAllRequests="true" > 
     <remove name="UrlRoutingModule"/>  
    </modules> 
    </system.webServer> 
+0

runAllManagedModulesForAllRequests =「真正的」單獨做由羅伯特·貝特格給出的工作,但解決方案也比較好。 – 2017-10-27 13:49:23

2

我的解決辦法,亂投醫後:

壞部署,舊PrecompiledApp.config被掛在我的部署位置,使一切不工作。

我認爲工作最終設置:

  • IIS 7.5,Win2k8r2 64,在web.config
  • 集成模式的應用程序池
  • 沒有什麼變化 - 這意味着路由無特殊處理。這裏是我對許多其他帖子的參考部分的快照。我使用FluorineFX,所以我有一個處理程序添加,但我並不需要任何其他:

    <system.web> 
        <compilation debug="true" targetFramework="4.0" /> 
        <authentication mode="None"/> 
    
        <pages validateRequest="false" controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/> 
        <httpRuntime requestPathInvalidCharacters=""/> 
    
        <httpModules> 
        <add name="FluorineGateway" type="FluorineFx.FluorineGateway, FluorineFx"/> 
        </httpModules> 
    </system.web> 
        <system.webServer> 
        <!-- Modules for IIS 7.0 Integrated mode --> 
        <modules> 
         <add name="FluorineGateway" type="FluorineFx.FluorineGateway, FluorineFx" /> 
        </modules> 
    
        <!-- Disable detection of IIS 6.0/Classic mode ASP.NET configuration --> 
        <validation validateIntegratedModeConfiguration="false" /> 
        </system.webServer> 
    
  • Global.ashx:(僅適用於任何音符的方法)

    void Application_Start(object sender, EventArgs e) { 
        // Register routes... 
        System.Web.Routing.Route echoRoute = new System.Web.Routing.Route(
          "{*message}", 
         //the default value for the message 
          new System.Web.Routing.RouteValueDictionary() { { "message", "" } }, 
         //any regular expression restrictions (i.e. @"[^\d].{4,}" means "does not start with number, at least 4 chars 
          new System.Web.Routing.RouteValueDictionary() { { "message", @"[^\d].{4,}" } }, 
          new TestRoute.Handlers.PassthroughRouteHandler() 
         ); 
    
        System.Web.Routing.RouteTable.Routes.Add(echoRoute); 
    } 
    
  • PassthroughRouteHandler的.cs - 這實現從http://andrew.arace.info/stackoverflowhttp://andrew.arace.info/#stackoverflow自動轉換這將隨後由Default.aspx的處理:

    public class PassthroughRouteHandler : IRouteHandler { 
    
        public IHttpHandler GetHttpHandler(RequestContext requestContext) { 
         HttpContext.Current.Items["IncomingMessage"] = requestContext.RouteData.Values["message"]; 
         requestContext.HttpContext.Response.Redirect("#" + HttpContext.Current.Items["IncomingMessage"], true); 
         return null; 
        } 
    } 
    
+0

你救了我的一天PrecompiledApp.config信息。 :-) 非常感謝。 – ekimpl 2016-04-19 11:02:59

0

在Windows資源管理器中取消選中此項。

「隱藏文件類型的擴展名已知類型的」

8

的解決方案建議

<system.webServer> 
    <modules runAllManagedModulesForAllRequests="true" > 
    <remove name="UrlRoutingModule"/>  
    </modules> 
</system.webServer> 

作品,但會降低性能,甚至可能會導致錯誤,因爲現在所有註冊的HTTP模塊在每次請求運行,不只是託管請求(例如.aspx)。這意味着模塊將在每次運行.jpg,.gif和的CSS的.html .PDF等

一個更明智的解決方案是包含這你的web.config:

<system.webServer> 
    <modules> 
    <remove name="UrlRoutingModule-4.0" /> 
    <add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" preCondition="" /> 
    </modules> 
</system.webServer> 

信用爲他去科林法爾。在http://www.britishdeveloper.co.uk/2010/06/dont-use-modules-runallmanagedmodulesfo.html查看他關於此主題的帖子。

1

,我的問題是一個新的服務器System.Web.Routing是3.5版本,而web.config中請求的版本4.0.0.0。 該決議是

%WINDIR%\框架\ v4.0.30319 \ ASPNET_REGIIS -i

%WINDIR%\ Framework64 \ v4.0.30319 \ ASPNET_REGIIS -i

0

在Global.asax.cs中有了這個爲我解決它。

protected void Application_Start() 
     { 
      AreaRegistration.RegisterAllAreas(); 
      RouteConfig.RegisterRoutes(RouteTable.Routes); 
     }