Asp.net IIS 7.5路由不工作(测试了所有常用方法)
我有一个客户,他在global.asax中添加了一个带有自定义路由的网页(无扩展): 不幸的是,此重定向在IIS 7.5上不起作用。我已经测试过:Asp.net IIS 7.5路由不工作(测试了所有常用方法),asp.net,routing,iis-7.5,Asp.net,Routing,Iis 7.5,我有一个客户,他在global.asax中添加了一个带有自定义路由的网页(无扩展): 不幸的是,此重定向在IIS 7.5上不起作用。我已经测试过: HTTP重定向是通过IIS安装的 尝试运行AllManagedModulesForallRequests=“true”(在web.config中) 使用UrlRoutingMode的手动添加(http://www.britishdeveloper.co.uk/2010/06/dont-use-modules-runallmanagedmodules
- HTTP重定向是通过IIS安装的
- 尝试运行AllManagedModulesForallRequests=“true”(在web.config中)
- 使用UrlRoutingMode的手动添加(http://www.britishdeveloper.co.uk/2010/06/dont-use-modules-runallmanagedmodulesfo.html)
<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>
看看这个:
我的解决方案,在尝试了所有方法之后: 糟糕的部署,一个旧的预编译app.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>
- PassthroughRouteHandler.cs-这实现了从到的自动转换,然后将由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; } }
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);
}
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;
}
}