微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

当我想在设置 coockie 后重定向时,它说 HTTP 错误 401.0 - 未经授权

如何解决当我想在设置 coockie 后重定向时,它说 HTTP 错误 401.0 - 未经授权

这是我的登录控制器

[HttpPost]
    public ActionResult Login(Loginviewmodel login,string ReturnUrl = "/Admin/pages/index")
    {
        if (ModelState.IsValid)
        {
            if (loginRepository.IsUserExist(login.UserName,login.Password))
            {
                FormsAuthentication.SetAuthCookie(login.UserName,login.RememberMe);
                return Redirect(ReturnUrl);
            }
            else
            {
                ModelState.AddModelError("UserName","Username and password is incorrect");
            }
        }
        return View();
    }

我在将 cookie 设置为管理区域后重定向它,但它给了我“HTTP 错误 401.0 - 未经授权”错误

我的管理区域控制器

[Authorize]
public class PagesController : Controller
{
    public ActionResult Index()
    {
        return View(pageRepository.GetAllPage());
    }
}

解决方法

我发现问题出在 web.config

必须在 web.config 中添加以下行:

<authentication mode="Forms">
  <forms name="Website" loginUrl="/Account/login" timeout="43200"></forms>
</authentication>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。