2011-10-08 40 views
0

如果用戶未被授權執行操作,則在HandleUnauthorizedRequest中,我將用戶重定向到錯誤操作。這導致302錯誤。更改授權屬性過濾器中的操作

例如從/Home/Index,用戶將被帶到/Error/Unauthorized

而不是重定向,如何更改filterContext.Response中的ActionResult,以便用戶在沒有重定向的情況下看到未經授權的頁面?

回答

0
filterContext.Response = new ViewResult 
{ 
    ViewName = "~/Views/Error/Unauthorized.cshtml" 
};