2011-07-15 16 views
3

私は使用していたWebアプリケーションを持っていますAsp.net MVC2。私はそれをMVC 3にアップグレードしましたが、今はOutputCacheの機能がそれ以上機能していないことがわかりました。以下に示すような単純なテストアクションを作成しました。MVC 2からアップグレードした後、Asp.net MVC 3はNinjectで動作しませんでしたか?

[OutputCache(Duration = 1000000, VaryByParam = "none")] 
public virtual ActionResult CacheTest(string name) 
    { 
    string message = string.Format("{0}: Time is {1}", name, DateTime.Now.ToLongTimeString()); 
    ViewData.Add("Message", message); 
    return View(); 
    } 

これは、常にそれがにキャッシュされていないことを示している現在の時刻を与えます。私はここに何かを逃していますか

詳細情報:私は新しいMvc3アプリケーションを作成すると問題なく動作します。私はこの問題があるアップグレードされたアプリケーションでのみ。

更新:私はNinjectも使用しています。 Ninjectの使用をやめると、OutputCacheが動作を開始します。

public class MvcApplication : System.Web.HttpApplication 
    { 
     public static void RegisterRoutes(RouteCollection routes) 
     { 
      routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 

      routes.MapRoute(
       "Default", // Route name 
       "{controller}/{action}.aspx/{id}", // URL with parameters 
       new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults 
      ); 

     } 

     protected void Application_Start() 
     { 
      RegisterDependencyResolver(); 

      AreaRegistration.RegisterAllAreas(); 

      RegisterRoutes(RouteTable.Routes); 
     } 

     protected void RegisterDependencyResolver() 
     { 
      var kernel = CreateKernel(); 
      DependencyResolver.SetResolver(new NinjectDependencyResolver(kernel)); 
     } 

     protected IKernel CreateKernel() 
     { 
      return new StandardKernel(); 
     } 
    } 
+0

奇妙な問題を再現できません。キャッシュは私のために働く。 –

+0

私は新しいMvc3アプリケーションを作成してもうまく動作します。私はこの問題があるアップグレードされたアプリケーションでのみ。 – Amitabh

+0

これは意味がありません。私にとって、このa)は再現できませんb)ちょうど意味がありません - Ninjectは 'OutputCacheAttribute'とは関係がありませんので、NinjectやMVCの複数のバージョンを持つようなものがあるはずです。 https://groups.google.com/forum/?fromgroups=#!topic/ninject/NtsBWNS4MJs –

答えて

6

正しいとASP.NET MVC 3でNinjectを使用する方法をお勧めします以下の通りです:

  1. ninject.mvc3 NuGetパッケージをインストールします。

    :これはASP.NET MVCと互換性のある最新バージョン3.

  2. は一度このプロジェクトにApp_Start/NinjectMVC3.csファイルを追加し、それはあなたがあなたのNinjectモジュールを登録しますRegisterServicesメソッド内でインストールされ得ることを保証します

    private static void RegisterServices(IKernel kernel) 
    { 
        var modules = new INinjectModule[] 
        { 
         // your modules here 
        }; 
        kernel.Load(modules); 
    }   
    
  3. NinjectDependencyResolverを含むGlobal.asaxからNinject固有のコードをすべて削除します。

これらの手順を試してみてください。問題が解決する場合があります。

+0

もありがとうございます。その作業は今素晴らしいです。 – Amitabh

関連する問題