1

I've integrated MVC into an old web forms app. The version ASP.NET version is 4.0.

The following configuration will cause the Default.aspx page to not be loaded by default when navigating to the domain. (i.e. http://www.myfakeeeeeeeeeeeedomain.com/)

  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
  </system.webServer>

However, if I switch the value to false, my default.aspx page will load by default when navigating to the domain, but...my MVC routing requests will then not work. How can I keep the MVC routing while at the same time having my default.aspx page display correctly?

Note: The "Default Page" option is correctly setup in IIS 7.

I can provide more info if needed.

contactmatt
  • 18,116
  • 40
  • 128
  • 186

1 Answers1

0

My question was answered by looking at this post: After add MapPageRoute to an asp.net mvc project, the site stops to enter in Home Controller

The actual code I implemented was as follows:

    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.MapPageRoute("DefaultPage", "", "~/Default.aspx", false, null, new RouteValueDictionary { { "outgoing", new CustomWebFormRouteConstraint() } });
        routes.MapRoute(
            "Default", // Route name
            "{controller}/{action}/{id}", // URL with parameters
            new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
        );

    }

    public class CustomWebFormRouteConstraint : IRouteConstraint
    {
        // Only match on incoming requests
        public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
        {
            return routeDirection == RouteDirection.IncomingRequest;
        }
    }
Community
  • 1
  • 1
contactmatt
  • 18,116
  • 40
  • 128
  • 186