MVC FormsAuthentication权限问题

禁用F3 2018-04-07 02:29:46
Authorize特性 登录成功总是报401
Login成功跳转到Index总是报401错误不解。


不知道是哪个地方授权失败了。登录已经执行跳转了。可为啥会授权失败呢?
...全文
268 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
禁用F3 2018-04-07
  • 打赏
  • 举报
回复
引用 3 楼 tangyanzhi1111 的回复:
authorize 要求action只能被认证的用户访问,否则 会出现401 unauthorized 提示 。 你啥都没设置,搞个几把。
那我设置,在登录如何设置呢?


[Authorize(Roles ="Admin")]
        public ActionResult Index()
        {
            ListPruduct = base.Context.Product.Include("FK_Table_Category").ToList();
            return View(ListPruduct);
        }
        public ActionResult ProductAdd(int id = 0)
        {
            if (id > 0)
            {
                var model = ListPruduct.Where(p => p.PK_ID == id).FirstOrDefault();
                return View(model);
            }
            return View(new Product());
        }


        [AllowAnonymous]
        public ActionResult Login(SystemUser user)
        {
            var login = base.Context.SystemUser.Where(a => a.Password == user.Password && a.Accounts == user.Accounts).FirstOrDefault();
            if (login != null)
            {
                System.Web.Security.FormsAuthentication.SetAuthCookie(login.Accounts, false,"UserName"); //登录这里要如何设置角色权限呢?
            
                return Redirect("Index");
            }       
            return View();
        }


 
江湖评谈 2018-04-07
  • 打赏
  • 举报
回复
authorize 要求action只能被认证的用户访问,否则 会出现401 unauthorized 提示 。

你啥都没设置,搞个几把。
禁用F3 2018-04-07
  • 打赏
  • 举报
回复
引用 1 楼 xuzuning 的回复:
401 是没有运行权限,是 iis 设置问题,与程序本身无关
我现在还没有用IIS,程序还在开发,现在调试发现问题,用的是VS自带的IIS Express
xuzuning 2018-04-07
  • 打赏
  • 举报
回复
401 是没有运行权限,是 iis 设置问题,与程序本身无关

110,537

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧