Tôi đã đọcChuyển đến một trang khác khi người dùng không được uỷ quyền trong asp.net MVC3
How to easily redirect if not authenticated in MVC 3? và Redirect to AccessDenied page when user is not authorized nhưng liên kết từ một câu trả lời (nghĩa http://wekeroad.com/2008/03/12/aspnet-mvc-securing-your-controller-actions/) không hoạt động.
tôi đặt
[Authorize(Users = "test")]
public class RestrictedPageController: Controller
{
public ActionResult Index()
{
return View();
}
....
}
Và trong web.config của tôi, tôi đã có
<authentication mode="Forms">
<forms loginUrl="~/Account/LogOn" timeout="2880" />
</authentication>
phù hợp với https://stackoverflow.com/a/6770583/998696
Nhưng khi tôi muốn truy cập /RestrictedPage/Index
, nó phải chuyển hướng tôi đến trang khác (từ bộ điều khiển khác). Thay vì điều này, các lỗi xuất hiện như:
Server Error in '/Project' Application.
The view 'LogOn' or its master was not found or no view engine supports the searched locations. The following locations were searched:
~/Views/Account/LogOn.aspx
~/Views/Account/LogOn.ascx
~/Views/Shared/LogOn.aspx
~/Views/Shared/LogOn.ascx
~/Views/Account/LogOn.cshtml
~/Views/Account/LogOn.vbhtml
~/Views/Shared/LogOn.cshtml
~/Views/Shared/LogOn.vbhtml
Trước khi đăng nhập, hình thức Logon
trang xuất hiện một cách chính xác nhưng lỗi ở trên xuất hiện khi truy cập vào trang /RestrictedPage/Index
. Tôi có thể đăng nhập với người dùng khác được ủy quyền để truy cập trang RestrictedPage
.
Lỗi của tôi và cách chuyển hướng thiết lập ở đâu?
Upvote và chấp nhận! Một lưu ý: phải sử dụng 'protected override void HandleUnauthorizedRequest (AuthorizationContext filterContext) {' để ghi đè lên phương thức, nếu không sẽ không hoạt động –
Cảm ơn bạn đã chỉ rằng .. cố định atonce! – VJAI