0

我正在将一个经典的 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 来实现这一点?

4

1 回答 1

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 }
        );
    }
于 2013-07-16T16:27:06.047 回答