【问题标题】:Routing HTTP Error 404.0 0x80070002路由 HTTP 错误 404.0 0x80070002
【发布时间】:2011-08-06 08:00:13
【问题描述】:

我已经在我的 ASP.NET 应用程序和我的 IIS7 开发机器上创建了路由规则,一切正常。当我将解决方案部署到也具有 IIS7 的产品服务器时,我在访问 URL 时收到错误 404(找不到页面)。也许有人可以指出问题出在哪里?

实际错误

HTTP 错误 404.0 - 未找到 您正在寻找的资源是 已删除、已更改名称或已 暂时不可用。详细的 错误信息Module IIS Web Core 通知 MapRequestHandler 处理程序静态文件错误代码 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));
                        }
                }

            }
}

【问题讨论】:

  • 你使用什么类型的路由? MVC ?
  • 我使用 System.Web.Routing.RouteCollection 类(.NET 4.0)
  • 你希望它被路由到什么 - pdf-button.aspx?我相信你已经意识到 0x80070002 = ERROR_FILE_NOT_FOUND

标签: asp.net iis-7 routing url-routing


【解决方案1】:

刚刚发现下面的行必须添加到web.config 文件中,现在在生产服务器上也一切正常。

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

【讨论】:

  • runAllManagedModulesForAllRequests="true" 单独完成了这项工作,但 Robert Bethge 给出的解决方案也更好。
【解决方案2】:

建议的解决方案

<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>

这要归功于 Colin Farr。在http://www.britishdeveloper.co.uk/2010/06/dont-use-modules-runallmanagedmodulesfo.html查看他关于此主题的帖子。

【讨论】:

    【解决方案3】:

    我的解决方案,在尝试了一切之后:

    糟糕的部署,一个旧的 PrecompiledApp.config 挂在我的部署位置,导致一切都无法正常工作。

    我的最终设置有效:

    • IIS 7.5,Win2k8r2 x64,
    • 集成模式应用程序池
    • 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;
          }
      }
      

    【讨论】:

    • 你用 PrecompiledApp.config 信息拯救了我的一天。 :-) 非常感谢。
    【解决方案4】:

    对我来说,问题是 System.Web.Routing 是 3.5 版的新服务器,而 web.config 请求的是 4.0.0.0 版。 决议是

    %WINDIR%\Framework\v4.0.30319\aspnet_regiis -i

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

    【讨论】:

      【解决方案5】:

      在 Global.asax.cs 中解决了这个问题。

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

      【讨论】:

        【解决方案6】:

        在 Windows 资源管理器中取消选中此项。

        “隐藏已知类型的文件类型扩展名”

        【讨论】:

          猜你喜欢
          • 2016-03-08
          • 2022-10-24
          • 2016-04-02
          • 2011-04-01
          • 1970-01-01
          • 2015-02-02
          • 2016-05-11
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多