我使用內置的授權過濾器的asp.net mvc。 我唯一的問題是,我不希望它重定向我的用戶登錄頁面,當他們沒有執行某個操作的權限時......它始終將他們帶到登錄頁面,即使它已經登錄(但沒有管理員角色)..我想能夠決定在他們試圖執行一個行動後,他們不應該把他們帶到哪裏?幫助與asp.net mvc授權
1
A
回答
2
子類AuthorizeAttribute並重寫HandleAuthorizationFailed()方法。此方法的默認邏輯是它將上下文的結果設置爲HttpUnauthorizedResult,但您可以通過此方法執行任何操作。然後使用這個新屬性爲目標方法賦予屬性。
0
由於Levi說您需要重寫AthorizeAttribute來創建自己的自定義AttributeFilter。像
public class CustomAuthorizeAttribute : AuthorizeAttribute {
public string Url { get; set; }
public override void OnAuthorization(AuthorizationContext filterContext) {
if (!filterContext.HttpContext.User.Identity.IsAuthenticated) { //or custom authorization logic
filterContext.HttpContext.Response.Redirect(Url);
}
base.OnAuthorization(filterContext);
}
}
[CustomAuthorizeAttribute(Url="/Admin/AccessDenied")]
public ActionResult Admin() {
return View();
}
採取
相關問題
- 1. 幫助使用asp.net mvc授權
- 2. LinqToTwitter授權幫助
- 3. 幫助與asp.net的MVC HTTPS
- 4. 幫助與軌道authlogic和授權
- 5. ASP.NET MVC 2授權與網關頁面
- 6. MVC路由與授權/授權標記
- 7. ASP.NET MVC 3定製授權
- 8. Asp.Net MVC授權選項
- 9. Asp.net MVC授權屬性
- 10. ASP.NET MVC授權過濾
- 11. ASP.NET MVC授權 - 自定義?
- 12. ASP.NET MVC:[授權]的對面
- 13. 使用ASP.NET MVC授權Twitter
- 14. ASP.NET MVC - 授權重構
- 15. ASP.NET MVC自定義授權
- 16. ASP.NET MVC 2授權問題
- 17. ASP.NET MVC網站授權
- 18. asp.net的MVC授權問題
- 19. ASP.NET MVC定製授權
- 20. 使用jQuery與ASP.NET MVC的幫助
- 21. ASP.NET MVC與jQuery SimpleModal和Ajax.BeginForm幫助
- 22. Asp.net MVC下拉列表與HTML幫助
- 23. 幫助與asp.net的MVC SelecList,Html.dropdownList和linqtosql
- 24. 幫助與asp.net的MVC和jQuery
- 25. 幫助與asp.net mvc選擇下拉
- 26. 自定義授權(權限)ASP.NET MVC
- 27. 幫助授權(角色=)] MVC 3 Windows身份驗證
- 28. 幫助MVC認證/授權解決方案
- 29. 需要幫助的理解ASP .Net MVC用戶認證/授權
- 30. WCF驗證/授權 - 需要幫助