gpt4 book ai didi

asp.net-mvc - 表单例份验证给出了一个太长的查询字符串

转载 作者:行者123 更新时间:2023-12-03 18:15:19 24 4
gpt4 key购买 nike

这个问题在这里已经有了答案:





ASP.NET MVC 5 : Endless redirect to the login page using the site template

(1 个回答)


7年前关闭。




我正在尝试进行(临时)登录,将用户存储在我的 web.config 文件中。
在 web.config 文件中添加拒绝后,它给了我这个错误

HTTP Error 404.15 - Not Found The request filtering module is configured to deny a request where the query string is too long.



网址看起来像这样
http://localhost/Account/Login?ReturnUrl=%2FAccount%2FLogin%3FReturnUrl%3D%252FAccount%252FLogin%253FReturnUrl%253D%25252FAccount%25252FLogin%25253FReturnUrl%25253D%2525252FAccount%2525252FLogin%2525253FReturnUrl%2525253D%252525252FAccount%252525252FLogin%252525253FReturnUrl%252525253D%25252525252FAccount%25252525252FLogin%25252525253FReturnUrl%25252525253D%2525252525252FAccount%2525252525252FLogin%2525252525253FReturnUrl%2525252525253D%252525252525252FAccount%252525252525252FLogin%252525252525253FReturnUrl%252525252525253D%25252525252525252FAccount%25252525252525252FLogin%25252525252525253FReturnUrl%25252525252525253D%2525252525252525252FAccount%2525252525252525252FLogin%2525252525252525253FReturnUrl%2525252525252525253D%252525252525252525252FAccount%252525252525252525252FLogin%252525252525252525253FReturnUrl%252525252525252525253D%25252525252525252525252FAccount%25252525252525252525252FLogin%25252525252525252525253FReturnUrl%25252525252525252525253D%2525252525252525252525252FAccount%2525252525252525252525252FLogin%2525252525252525252525253FReturnUrl%2525252525252525252525253D%252525252525252525252525252FAccount%252525252525252525252525252FLogin%252525252525252525252525253FReturnUrl%252525252525252525252525253D%25252525252525252525252525252FAccount%25252525252525252525252525252FLogin%25252525252525252525252525253FReturnUrl%25252525252525252525252525253D%2525252525252525252525252525252FAccount%2525252525252525252525252525252FLogin%2525252525252525252525252525253FReturnUrl%2525252525252525252525252525253D%252525252525252525252525252525252FAccount%252525252525252525252525252525252FLogin%252525252525252525252525252525253FReturnUrl%252525252525252525252525252525253D%25252525252525252525252525252525252FAccount%25252525252525252525252525252525252FLogin%25252525252525252525252525252525253FReturnUrl%25252525252525252525252525252525253D%2525252525252525252525252525252525252FAccount%2525252525252525252525252525252525252FLogin%2525252525252525252525252525252525253FReturnUrl%2525252525252525252525252525252525253D%252525252525252525252525252525252525252FAccount%252525252525252525252525252525252525252FLogin%252525252525252525252525252525252525253FReturnUrl%252525252525252525252525252525252525253D%25252525252525252525252525252525252525252F

(不否认它设置了cookie,但我仍然可以访问所有页面)

这是它在我的 web.config 中的样子
    <authentication mode="Forms">
<forms loginUrl="~/Account/Login" name=".ASPXAUTH" slidingExpiration="true" timeout="1440" path="/" defaultUrl="~/">
<credentials passwordFormat="Clear">
<user name="matchUser80" password="123Match789"/>
</credentials>
</forms>
</authentication>

<authorization>
<deny users="?" />
</authorization>

还有我的 Controller
        [HttpPost]
public ActionResult Login(LoginModel model, string returnUrl)
{
if (!ModelState.IsValid)
{
return View(model);
}

if (FormsAuthentication.Authenticate(model.UserName, model.Password))
{
FormsAuthentication.SetAuthCookie(model.UserName, false);
FormsAuthentication.RedirectFromLoginPage(model.UserName, false);
if (returnUrl != null)
{
return Redirect(returnUrl);
}
return View();
}

ModelState.AddModelError(string.Empty, "Wrong username or password");
return View(model);
}

我正在使用 MVC 5。

最佳答案

您应该使用属性而不是 web.config 配置来授权您的 mvc 应用程序。 Web 配置配置应仅用于 Web 表单应用程序。

使用 [AllowAnonymous] 装饰您的登录操作(获取和发布版本)属性。

用户 [Authorize]其他 Controller 的属性。

阅读 this article了解如何保护您的 mvc 应用程序。

更新

我用默认的 mvc 项目在本地重现了你的问题,我的 web.config 中有这个:

<system.webServer>
<modules>
<remove name="FormsAuthentication" />
</modules>
</system.webServer>

在我评论 <remove name="FormsAuthentication" /> 后一切都开始工作了部分

关于asp.net-mvc - 表单例份验证给出了一个太长的查询字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26219424/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com