4.0 ASP.NET和MVC混合模式网站的默认页面问题

时间:2013-07-16 16:25:43

标签: asp.net asp.net-mvc-4 asp.net-mvc-routing

我正在转换经典的ASP.NET 4.0站点以使用MVC。随着时间的推移,我将ASP.NET代码迁移到MVC,但在转换过程中,这两种技术都将被使用。

如果我导航到默认页面(即http://mywebsite.com/),则MVC路由接管并返回以下消息。

  

此请求已被阻止,因为敏感信息可能是   当在GET请求中使用它时向第三方网站公开。   要允许GET请求,请将JsonRequestBehavior设置为AllowGet

如果我使用http://mywebsite.com/default.aspx,那么一切正常。

我的路线配置看起来像......

public class RouteConfig
{
    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        //ignore aspx pages (web forms take care of these)
        routes.IgnoreRoute("{resource}.aspx/{*pathInfo}");

        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
        );
    }
}

注意我忽略了.aspx页面请求,因此MVC管道会忽略这些请求。但是,我需要“没有指定页面”的默认请求来处理default.aspx。如何更改上述代码或配置站点/ IIS以实现此目的?

1 个答案:

答案 0 :(得分:0)

我删除了默认路由,现在根据需要进行操作。

    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        //ignore aspx pages (web forms take care of these)
        routes.IgnoreRoute("{resource}.aspx/{*pathInfo}");

        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { id = UrlParameter.Optional }
        );
    }