路由 HTTP 错误 404.0 0x80070002 [英] Routing HTTP Error 404.0 0x80070002
问题描述
我已经在我的 ASP.NET 应用程序和我的 IIS7 开发机器上创建了路由规则,一切正常.当我将解决方案部署到也有 IIS7 的 prod 服务器时,我在访问 URL 时收到错误 404(找不到页面).也许有人可以指出问题出在哪里?
I have created routing rules in my ASP.NET application and on my Dev machine at IIS7 everything works fine. When I deploy solution to prod server which has also IIS7 I get error 404 (page not found) while accessing URL. Maybe someone could point where is the problem?
实际错误
HTTP 错误 404.0 - 未找到您正在寻找的资源已经已删除、更改名称或暂时不可用.详细的错误信息Module IIS Web Core通知 MapRequestHandler处理程序静态文件错误代码0x80070002 请求的 URLhttp://xxx.xxx.xxx.xxx:80/pdf-button物理路径C:wwwpathtoprojectpdf-button 登录方法匿名登录用户匿名
HTTP Error 404.0 - Not Found The resource you are looking for has been removed, had its name changed, or is temporarily unavailable. Detailed Error InformationModule IIS Web Core Notification MapRequestHandler Handler StaticFile Error Code 0x80070002 Requested URL http://xxx.xxx.xxx.xxx:80/pdf-button Physical Path C:wwwpathtoprojectpdf-button Logon Method Anonymous Logon User Anonymous
我的实际代码
<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
文件中,现在在生产服务器上一切正常.
Just found that lines below must be added to web.config
file, now everything works fine on production server too.
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" >
<remove name="UrlRoutingModule"/>
</modules>
</system.webServer>
这篇关于路由 HTTP 错误 404.0 0x80070002的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!