【问题标题】:IIS 7.5 routing not working (all usual methods tested)IIS 7.5 路由不起作用(已测试所有常用方法)
【发布时间】:2011-08-24 19:58:01
【问题描述】:

我有一个客户,他有一个网页,在 global.asax 中添加了自定义路由(它们是无扩展名的):

Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
Routing.RouteTable.Routes.Clear()
Routing.RouteTable.Routes.MapPageRoute("Key1", "String", "~/Route")

不幸的是,这种重定向在 IIS 7.5 上不起作用。我已经测试过了:

  • HTTP 重定向是通过 IIS 安装的
  • 尝试运行AllManagedModulesForAllRequests="true"(在web.config 中)
  • 使用手动添加的 UrlRoutingMode (http://www.britishdeveloper.co.uk/2010/06/dont-use-modules-runallmanagedmodulesfo.html)

池处于集成模式,4.0。这台服务器运行了很多 MVC3 页面,并且默认使用路由。

任何光线都会非常感激!谢谢

================================================ ========================

编辑:好的,我找不到任何解决方案。

在 webconfig 中,在程序集中:

<add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />

在 system.webServer:

<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<defaultDocument>
<files><add value="Page.aspx" /></files>
</defaultDocument>
<modules runAllManagedModulesForAllRequests="true">
<remove name="UrlRoutingModule"/>
<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule,System.Web.Routing,Version=4.0.0.0,Culture=neutral,PublicKeyToken=31BF3856AD364E35" />
   </modules>



</system.webServer>

【问题讨论】:

    标签: asp.net routing iis-7.5


    【解决方案1】:

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

    糟糕的部署,一个旧的 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;
          }
      }
      

    【讨论】:

      【解决方案2】:

      【讨论】:

      • ¡感谢IrishChieftain!,但不幸的是,这正是我之前发布和检查过的链接。我已经尝试在发布之前解决问题。
      • 您能具体说明一下这个项目的类型 - Web 表单应用程序项目吗? MVC 页面是在单独的项目中,还是您尝试混合使用它们(不推荐)?
      • 再次感谢,我不能修改应用程序,只要我只是托管它。不知道为什么,当没有 ASPX 页面存在时,IIS 无法管理请求。我试试经典模式。
      猜你喜欢
      • 1970-01-01
      • 2015-11-26
      • 1970-01-01
      • 2013-07-26
      • 1970-01-01
      • 2018-01-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多