gpt4 book ai didi

c# - ASP.NET MVC Windows 身份验证拒绝工作

转载 作者:太空狗 更新时间:2023-10-30 00:39:57 26 4
gpt4 key购买 nike

我使用 Visual Studio 2015 创建了一个 MVC Web 应用程序。我的目标是根据需要将身份验证模式从无更改为 Windows 身份验证,以便我可以使用 @User.Identity.Name 方法来识别用户。到目前为止我尝试过的内容的简短总结:

项目属性

  • 设置匿名身份验证:禁用
  • 设置 Windows 身份验证:启用

Web.config

  • maxUrlLength="65536" 属性添加到 httpRuntime 标记
  • maxQueryStringLength="10240" 属性添加到 httpRuntime 标记
  • 添加<authentication mode="Windows"/><system.web> 内标签
  • 添加 system.webServer 标签(无论何时我添加它都会以 ERR_TOO_MANY_REDIRECTS 结尾):

    <system.webServer>
    <security>
    <requestFiltering>
    <requestLimits maxUrl="10999" maxQueryString="2097151" />
    </requestFiltering>
    </security>
    </system.webServer>

window

  1. 在控制面板中打开“程序和功能”
  2. 选择“转Windows 功能开启或关闭”。
  3. 导航到 Internet Information Services > World Wide Web Services > Security 并确保选中 Windows 身份验证节点

IIS Express

我尝试从头开始创建一个新项目,并在项目设置过程中巧妙地选择 Windows 身份验证。这工作正常,所以我相信我的 IISExpress 设置是 100% 正确的。我什至检查了 applicationhost.config 文件,它没有针对我的特定项目的条目。同样,如果我在创建新项目时选择正确的身份验证,它就可以正常工作。


当我尝试运行 Visual Studio 项目时,以上似乎都不起作用,并且都以 IIS 错误告终:

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

这是 URL 在 IIS 错误页面中的样子:

http://localhost:52728/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

如您所知,我得到了一个无限重定向循环,这可能是我无法正常工作的原因。但是我不知道是什么原因造成的。非常感谢任何帮助。

最佳答案

我猜我能够回答我自己的问题,因为我刚刚开始工作。对于将来遇到类似错误的人来说可能会派上用场。

解决方案:我不得不在 App_Start/Startup.Auth.cs 中注释掉以下代码:

 app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login")
});
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

关于c# - ASP.NET MVC Windows 身份验证拒绝工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32139845/

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