【发布时间】:2012-11-25 10:11:20
【问题描述】:
我的网站新闻部分有一个简单的路由。路由适用于几乎所有 URL 之类的
http://www.abc.com/Default.aspx
http://www.abc.com/Default.aspx?PageId=3
http://www.abc.com/Latest-News-Details.aspx?PageID=28&NewsID=39
仅当我尝试使用 http://www.abc.com 访问网站时才会出现问题,由于某种原因它会将其重定向到自定义错误页面,我无法跟踪错误源我无法在本地主机上生成任何此类错误。
代码示例
global.asx 文件
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
RegisterRoutes(RouteTable.Routes);
//RouteDebug.RouteDebugger.RewriteRoutesForTesting(RouteTable.Routes);
}
public static void RegisterRoutes(RouteCollection routes)
{
routes.Ignore("{*allaspx}", new { allaspx = @".*\.aspx(/.*)?" });
routes.Ignore("{*allcss}", new { allcss = @".*\.css(/.*)?" });
routes.Ignore("{*alljpg}", new { alljpg = @".*\.jpg(/.*)?" });
routes.Ignore("{*alljs}", new { alljs = @".*\.js(/.*)?" });
routes.Add(new System.Web.Routing.Route("{resource}.css/{*pathInfo}", new System.Web.Routing.StopRoutingHandler()));
routes.Add(new System.Web.Routing.Route("{resource}.js/{*pathInfo}", new System.Web.Routing.StopRoutingHandler()));
////For News
routes.MapPageRoute("NewsRoute", "{NewsID}/{PageID}/{NewsTitle}", "~/Latest-News-Details.aspx", false,
new RouteValueDictionary {
{ "NewsID", "0" },
{ "PageID", "0"},
{ "NewsTitle", "event-not-found" }},
new RouteValueDictionary {
{ "NewsID", "[0-9]{1,8}" },
{ "PageID", "[0-9]{1,8}" }
});
}
现在我已经禁用了新闻部分的路由,如果我不注释上述路由代码,它仍然会产生错误。
我不确定是什么导致了问题。
我如何处理 http://www.abc.com 等默认域的根目录
在这方面我将不胜感激
【问题讨论】:
-
您是否在 IIS 中设置了默认文档?
-
如果路由被禁用,它可以工作,我认为问题出在路径
标签: asp.net c#-4.0 asp.net-routing