相关疑难解决方法(0)

当用户未在asp.net mvc3中授权时,重定向到另一个页面

我读了

如果在MVC 3中未经过身份验证,如何轻松重定向?当用户未获得授权但来自答案的链接(表示http://wekeroad.com/2008/03/12/aspnet-mvc-securing-your-controller-actions/)不起作用, 将重定向到AccessDenied页面.

我放

[Authorize(Users = "test")]
    public class RestrictedPageController: Controller
    {

        public ActionResult Index()
        {
           return View();
        }

 ....
    }
Run Code Online (Sandbox Code Playgroud)

在我的web.config中,我已经

 <authentication mode="Forms">
      <forms loginUrl="~/Account/LogOn" timeout="2880" />
 </authentication>
Run Code Online (Sandbox Code Playgroud)

相应地使用/sf/answers/473940841/

但是当我想要访问时/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
Run Code Online (Sandbox Code Playgroud)

登录前,Logon页面窗体正确显示,但访问 …

c# asp.net asp.net-mvc asp.net-mvc-3

21
推荐指数
2
解决办法
5万
查看次数

asp.net mvc添加到AUTHORIZE属性

如何创建自定义属性以扩展MVC中的现有Authorize属性?

asp.net asp.net-mvc attributes

12
推荐指数
2
解决办法
2万
查看次数

标签 统计

asp.net ×2

asp.net-mvc ×2

asp.net-mvc-3 ×1

attributes ×1

c# ×1