【发布时间】:2012-06-11 07:10:21
【问题描述】:
我读过
How to easily redirect if not authenticated in MVC 3? 和 Redirect to AccessDenied page when user is not authorized 但来自答案的链接(表示 http://wekeroad.com/2008/03/12/aspnet-mvc-securing-your-controller-actions/)不起作用。
我放了
[Authorize(Users = "test")]
public class RestrictedPageController: Controller
{
public ActionResult Index()
{
return View();
}
....
}
在我的 web.config 中,我已经
<authentication mode="Forms">
<forms loginUrl="~/Account/LogOn" timeout="2880" />
</authentication>
根据https://stackoverflow.com/a/6770583/998696
但是当我想访问/RestrictedPage/Index 时,它必须将我重定向到其他页面(从其他控制器)。而不是这个,错误看起来像:
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
登录前,Logon页面表单正确显示,但访问/RestrictedPage/Index页面时出现上述错误。我可以使用不同的用户登录以访问RestrictedPage 页面。
我的错误在哪里以及如何设置重定向?
【问题讨论】:
标签: c# asp.net asp.net-mvc asp.net-mvc-3