您好我想實現一個自定義的授權過濾ASP.NET個IAuthorizationFilter OnAuthorization
//The Authourization attribute on a controller
public class CustomAdminAuthorizationFilter : IAuthorizationFilter
{
private readonly IAuthentication _authentication;
public SageAdminAuthorizationFilter(IAuthentication authentication)
{
_authentication = authentication;
}
public void OnAuthorization(AuthorizationContext filterContext)
{
bool result = _authentication.Authorize(filterContext.HttpContext);
}
}
正如你可以在OnAuthorization我得到一個結果是假的真見。 我需要設置什麼來返回我從哪裏來?
編輯:
它似乎仍然直扔我在日誌中
頁我注入IAuthetication
this.BindFilter<CustomAdminAuthorizationFilter>(FilterScope.Controller, 0);
Bind<IAuthentication>().To<CustomAuthenticationService>();
然後我裝飾我的動作在控制器等等。
[Authorize]
public ActionResult Index()
{
ViewBag.Title = "Welcome";
ViewBag.Message = "Welcome to ASP.NET MVC!";
return View();
}
在使用
<authentication mode="Forms">
<forms loginUrl="~/Account/LogOn" timeout="2880" />
</authentication>
我的web.config林如果有這樣的改變?
任何幫助將不勝感激。
這個回答你的問題? – hunter 2011-11-29 14:00:28