Tom*_*mas 9 asp.net routing iis-7 url-routing
我在我的ASP.NET应用程序和IIS7上的Dev机器上创建了路由规则,一切正常.当我将解决方案部署到也有IIS7的prod服务器时,我在访问URL时收到错误404(找不到页面).也许有人可以指出问题出在哪里?
实际错误
HTTP错误404.0 - 未找到您要查找的资源已被删除,名称已更改或暂时不可用.详细错误InformationModule IIS Web核心通知MapRequestHandler处理程序StaticFile错误代码0x80070002请求的URL http://xxx.xxx.xxx.xxx:80/pdf-button 物理路径C:\ www\pathtoproject\pdf-button登录方法匿名登录用户匿名
我的实际代码
<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));
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
Tom*_*mas 25
刚刚发现下面的行必须添加到web.config文件中,现在一切都在生产服务器上正常工作.
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" >
<remove name="UrlRoutingModule"/>
</modules>
</system.webServer>
Run Code Online (Sandbox Code Playgroud)
小智 12
解决方案建议
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" >
<remove name="UrlRoutingModule"/>
</modules>
</system.webServer>
Run Code Online (Sandbox Code Playgroud)
但是可以降低性能,甚至可能导致错误,因为现在所有已注册的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>
Run Code Online (Sandbox Code Playgroud)
归功于他的归功于Colin Farr.在http://www.britishdeveloper.co.uk/2010/06/dont-use-modules-runallmanagedmodulesfo.html上查看关于此主题的帖子.
| 归档时间: |
|
| 查看次数: |
99996 次 |
| 最近记录: |