【问题标题】:Why is MapPageRoute / RedirectToRoute working on dev machine but not on production server?为什么 MapPageRoute / RedirectToRoute 在开发机器上工作而不在生产服务器上工作?
【发布时间】:2013-05-21 00:37:02
【问题描述】:

我有一个常规的 webforms 项目(非 MVC),并且我成功实现了 MapPageRoute 和 RedirectToRoute 场景。页面路由是通过数据库查找完成的,因为我正在翻译查询字符串(例如 ?filter=112 到 /my-friendly-url)。它在我运行 VWD 2010 Express 和包含的 ASP.NET 开发服务器的开发机器上运行良好。 ASP.NET 版本是 4.0.30319.272。但是,当我在生产 (iis7) 框上运行项目时,我在映射页面上收到页面未找到错误。站点/页面的其余部分运行良好。我的直觉是页面处理是问题的根源,但我不知道它是什么或为什么。这可能与 iis7 如何处理目录与文件名以及我的程序将物理 .aspx 路由到目录样式名称可能产生的干扰有关。我在这方面的 iis7 和 web.config 知识有点薄弱。

这里是我的 global.asax 的摘录:

   void Application_Start(object sender, EventArgs e)
   {
      // Code that runs on application startup
      RegisterRoutes(RouteTable.Routes);
   }

   public static void RegisterRoutes(RouteCollection routes)
   {
      routes.Clear();
      routes.RouteExistingFiles = false;
      routes.Ignore("{resource}.axd/{*pathInfo}"); //ignore axd files, prevents javascript/routing collisions
      routes.MapPageRoute("Education", "{category}/{section}", "~/product/education/default.aspx");
      routes.MapPageRoute("EducationLanding", "{category}", "~/product/education/default.aspx");
   }

Web.config:

的处理程序部分
 <handlers>
     <remove name="StaticFile" />
     <remove name="PageHandlerFactory-Integrated-4.0" />
     <add verb="*" path="ajax/*.ashx" name="Ajax" type="Ajax.PageHandlerFactory, Ajax" />
     <add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
     <add name="PageHandlerFactory-Integrated-4.0" path="*.aspx" verb="GET,HEAD,POST,DEBUG" type="System.Web.UI.PageHandlerFactory" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode,runtimeVersionv4.0" />
     <add name="StaticFile" path="*" verb="*" modules="StaticFileModule,DefaultDocumentModule,DirectoryListingModule" resourceType="Either" requireAccess="Read" />  
  </handlers>

提前致谢, 约翰

【问题讨论】:

    标签: c# asp.net iis-7


    【解决方案1】:

    查看页面处理将我带到 web.config 的模块部分,我在 SO (IIS 7 ignores MapPageRoute without file extentions) 上找到了答案。为什么我在以前的所有搜索中都没有找到这个,我不知道。看:

    <system.webServer>
        <modules runAllManagedModulesForAllRequests="true"/>
    </system.webServer>
    

    谢谢@克里斯托夫

    【讨论】:

      【解决方案2】:

      这一切都很好,但不要忘记需要重新启动服务器才能触发 global.asax 的 Application_Start

      【讨论】:

      • 看来这个问题已经有了一个公认的答案,它解释了解决方案需要的不仅仅是重新启动服务器。
      猜你喜欢
      • 2011-05-30
      • 2022-07-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-02
      • 2021-06-15
      • 1970-01-01
      • 2016-11-05
      相关资源
      最近更新 更多