2012-09-06 67 views
1

我已經將MVC整合到一箇舊的Web表單應用程序中。 ASP.NET版本的版本是4.0。Asp.net默認頁面不返回runAllManagedModulesForAllRequests = true

以下配置將導致Default.aspx頁面在導航到域時默認不加載。 (即http://www.myfakeeeeeeeeeeeedomain.com/

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

但是,如果我的價值轉換爲假,我Default.aspx頁面導航到該域時會默認加載的,但是...我的MVC路由請求不會再去工作。我如何保持MVC路由,同時讓我的default.aspx頁面正確顯示?

注:「默認頁」選項是正確的設置在IIS 7

,如果需要,我可以提供更多的信息。

回答

0

我的問題是通過看這個帖子回答:After add MapPageRoute to an asp.net mvc project, the site stops to enter in Home Controller

我實現的實際代碼是如下:

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; 
     } 
    }