IIS 7.5路由未正常工作(已测试所有常规方法)

3
我有一个客户拥有一个带有自定义路由的网页,这些路由被添加在 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上安装
  • 尝试将runAllManagedModulesForAllRequests设置为“true”(在web.config中)
  • 使用UrlRoutingMode的手动添加(http://www.britishdeveloper.co.uk/2010/06/dont-use-modules-runallmanagedmodulesfo.html)

池处于集成模式下,版本为4.0。此服务器正在运行大量MVC3页面,并且它们默认使用路由。

任何帮助都将非常感激!谢谢

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

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

在assemblies标签内的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>
2个回答

1

谢谢IrishChieftain!但很遗憾,那正是我之前发布并检查过的链接。我在发帖前已经尝试解决这个问题了。 - Jacob
你能具体说明一下这个项目的类型吗 - Web表单应用程序项目?MVC页面是在单独的项目中还是你试图混合它们(不推荐)? - IrishChieftain
给RouteMagic一个机会?http://haacked.com/archive/2011/01/30/introducing-routemagic.aspx - IrishChieftain
再次感谢,只要我仅仅是托管应用程序,就无法修改它。不知道为什么,但当没有 ASPX 页面存在时,IIS 无法处理请求。我会尝试使用经典模式。 - Jacob

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>
        <!-- IIS 7.0集成模式的模块 -->
        <modules>
          <add name="FluorineGateway" type="FluorineFx.FluorineGateway, FluorineFx" />
        </modules>
    
        <!-- 禁用IIS 6.0 /经典模式ASP.NET配置的检测 -->
        <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}",
            //消息的默认值
              new System.Web.Routing.RouteValueDictionary() { { "message", "" } },
            //任何正则表达式限制(即@"[^\d].{4,}"表示“不以数字开头,至少4个字符”
              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/stackoverflow自动转换为http://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;
        }
    }
    

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接