首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >当用户未在asp.net mvc3中获得授权时重定向到另一个页面

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

Stack Overflow用户
提问于 2012-06-07 16:28:19
回答 4查看 58.9K关注 0票数 23

我读过

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页面。

我的错误在哪里?如何设置重定向?

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10928277

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档