ASP.NET MVC Windows身份验证拒绝工作
我已经使用Visual Studio 2015创建了一个MVC Web应用程序。我的目标是将身份验证模式从none更改为Windows Authentication,因此我可以使用@ User.Identity.Name方法来标识用户。 以下是我迄今尝试过的简短摘要:
项目属性
Web.config文件
<system.web>
标记中添加<authentication mode="Windows"/>
添加system.webServer标记(每当我添加它时,都会以ERR_TOO_MANY_REDIRECTS结尾):
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxUrl="10999" maxQueryString="2097151" />
</requestFiltering>
</security>
</system.webServer>
视窗
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.
这是在IIS错误页面中URL的样子:
HTTP://本地主机:52728 /帐号/登录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%2525252525252525252525252FAc 计数%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%2525252525252525252525252525252525253FReturn URL%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: Users [您的用户名] Documents IISExpress Logs [应用程序名称]以获取任何错误详细信息或URL。
链接地址: http://www.djcxy.com/p/42081.html