2011-03-02 14 views
12

MVC2アプリケーションの起動速度を向上させようとしています。ASP.NET MVCの起動パフォーマンスを向上させる

私は、パフォーマンスのサンプリングの最初のラウンドをした、そして

MvcAreaRegistration.RegisterAllAreas 

は、起動時間のほとんどを占めていることが表示されます。

私はhereを手動で登録することができますが、それを試してみたいと思いますが、そのページで構文がどのように機能するかわかりません。

私の最初の質問は次のようなものです。私は自分のエリアを手動でどのように登録できますか?

答えて

5

まず、このような自分のGlobal.asaxでヘルパーメソッドを用意:

private static void RegisterArea<T>(RouteCollection routes, object state) where T : AreaRegistration 
{ 
    AreaRegistration registration = (AreaRegistration)Activator.CreateInstance(typeof(T)); 
    AreaRegistrationContext registrationContext = new AreaRegistrationContext(registration.AreaName, routes, state); 
    string areaNamespace = registration.GetType().Namespace; 
    if (!String.IsNullOrEmpty(areaNamespace)) 
    registrationContext.Namespaces.Add(areaNamespace + ".*"); 
    registration.RegisterArea(registrationContext); 
} 

今、あなたはこのようのApplication_Startで手動登録のため、このヘルパーメソッドを使用することができます。

//Replace AreaRegistration.RegisterAllAreas(); with lines like those 
RegisterArea<FirstAreaRegistration>(RouteTable.Routes, null); 
RegisterArea<SecondAreaRegistration>(RouteTable.Routes, null); 

AreaRegistrationクラスがされています新しいエリアを追加するときにVisual Studioによって作成されたもので、エリア/エリア名のディレクトリで見つけることができます。

0

これを手で完全に行うことができ、RegisterArea実装を使用しないでください。

チェックこの記事:要するに http://www.philliphaydon.com/2011/07/mvc-areas-routes-order-of-routes-matter/

- あなたのルートに "エリア" DataTokenを追加する必要があります。

private void RegisterAreas(RouteCollection routes) 
{ 
    // AreaRegistration.RegisterAllAreas(); 
    var route = routes.MapRoute(
     "MyArea_Default", 
     "MyArea/{controller}/{action}/{id}", 
     new { controller = "App", action = "Index", id = UrlParameter.Optional }, 
     new string[] { "MyProject.Areas.*" } 
    ).DataTokens.Add("Area", "CDR"); 
} 
関連する問題