问题描述
|
我已经在ASP.NET应用程序和IIS7的Dev计算机上创建了路由规则,一切正常。当我将解决方案部署到也具有IIS7的产品服务器时,访问URL时出现错误404(找不到页面)。也许有人可以指出问题出在哪里?
实际错误
HTTP错误404.0-找不到
您正在寻找的资源一直
已删除,更名或
暂时不可用。详细
错误信息模块IIS Web核心
通知MapRequestHandler
处理程序StaticFile错误代码
0x80070002请求的URL
http://xxx.xxx.xxx.xxx:80/pdf-button
物理路径
C:\\ www \\ pathtoproject \\ pdf-按钮登录
方法匿名登录用户匿名
我的实际代码
<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));
}
}
}
}
解决方法
刚刚发现必须将以下行添加到
web.config
文件中,现在一切在生产服务器上也可以正常工作。
<system.webServer>
<modules runAllManagedModulesForAllRequests=\"true\" >
<remove name=\"UrlRoutingModule\"/>
</modules>
</system.webServer>
,解决方案建议
<system.webServer>
<modules runAllManagedModulesForAllRequests=\"true\" >
<remove name=\"UrlRoutingModule\"/>
</modules>
</system.webServer>
可以,但是会降低性能,甚至可能导致错误,因为现在所有已注册的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>
归功于他对Colin Farr的支持。在http://www.britishdeveloper.co.uk/2010/06/dont-use-modules-runallmanagedmodulesfo.html上查看有关此主题的文章。
,尝试一切后,我的解决方案:
部署不良,我的部署位置周围挂着一个旧的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/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;
}
}
,对我来说,问题是System.Web.Routing为3.5版的新服务器,而web.config请求为4.0.0.0版。
决议是
%WINDIR%\\ Framework \\ v4.0.30319 \\ aspnet_regiis -i
%WINDIR%\\ Framework64 \\ v4.0.30319 \\ aspnet_regiis -i
,在Windows资源管理器中取消选中此选项。
\“隐藏已知类型的文件扩展名\”
,在Global.asax.cs中拥有此功能可以为我解决。
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RouteConfig.RegisterRoutes(RouteTable.Routes);
}