【发布时间】:2014-02-24 08:14:57
【问题描述】:
我正在开发一个 asp.net 4.0 网络表单站点,并且正在尝试路由。 我认为它工作得很好,直到我发现我的一个页面在使用路由时被加载了两次。
我在global.asax.cs:
private void Application_Start(object sender, EventArgs e)
{
RegisterRoute(RouteTable.Routes);
}
void RegisterRoute(RouteCollection routes)
{
routes.MapPageRoute("NoRegion", "{language}/region", "~/region.aspx");
routes.MapPageRoute("region", "{region}/{language}/region", "~/region.aspx");
}
为什么region.aspx 在使用任一路由时会加载两次?
编辑:嗯,我有一个 Application_Error 设置,当有 404 时重定向到默认页面(区域)。发生的事情是该站点找不到 favicon.ico 所以它重定向回页面,因此双重加载。所以我删除它并重试它,但它没有工作!我在这里拉扯我的头发。
编辑 2:添加一个 favicon.ico '修复'它。
编辑 3:web.config 还启用了 CustomErrors:<error statusCode="404" redirect="eng/region?" />。删除它更能修复它!
【问题讨论】:
-
登录只是说我的 ASP.NET MVC Web 应用程序也有这个问题。现在通过添加一个 favicon.ico 文件完全解决了。
标签: asp.net .net webforms routing asp.net-4.0