2011-04-15 62 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); 
     } 
相关问题