2012-02-05 42 views
0

我創建了一個ASP.Net MVC Web應用程序,並使用NuGet安裝Ninject版本2.2.1.4和Ninject.MVC3版本2.2.2.0。此應用程序使用表單認證。我有獲得授權的工作問題......System.Web.Mvc.AuthorizeAttribute不適用於NinjectDependencyResolver

這是在Global.asax中我Application_Start方法中:

protected void Application_Start() 
{ 
    AreaRegistration.RegisterAllAreas(); 

    RegisterGlobalFilters(GlobalFilters.Filters); 
    RegisterRoutes(RouteTable.Routes); 

    var kernel = new StandardKernel(); 
    // binding code goes here... 

    // Remove this dependency resolver and Authorisation will work... 
    DependencyResolver.SetResolver(new NinjectDependencyResolver(kernel)); 
} 

而我在我的控制器操作之一:

[Authorize(Roles = "Admin")] 
public ActionResult About() 
{ 
    return View(); 
} 

而且我的web.config的驗證部分:

<authentication mode="Forms"> 
    <forms loginUrl="~/Account/LogOn" timeout="2880" /> 
</authentication> 

問題是未授權d用戶直接轉到關於視圖,而不是被重定向到LogOn。我知道問題出在NinjectDependencyResolver,因爲我從Application_Start中刪除了「DependencyResolver.SetResolver ...」行,未授權的用戶被重定向。

我會很感激您的幫助。

問候,菲爾

回答

相關問題