ASP.NET MVC Windows Authentication refusing to work
I've created a MVC Web Application using Visual Studio 2015. My goal is to change the authentication mode from none to Windows Authentication as I need so I can use the @User.Identity.Name method to identify the user. A short summary of what I've tried so far:
Project Properties
Web.config
<authentication mode="Windows"/>
within the <system.web>
tag adding the system.webServer tag (this ends up in a ERR_TOO_MANY_REDIRECTS whenever I add it):
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxUrl="10999" maxQueryString="2097151" />
</requestFiltering>
</security>
</system.webServer>
Windows
IIS Express
I tried creating a new project from scratch and neatly selecting Windows Authentication during the setup of the project. This works fine, so I believe my IISExpress settings are 100% correct . I even checked the applicationhost.config file and it doesn't have an entry for my specific project. Again, it works just fine if I select the correct authentication when creating a new project.
None of the above seems to work and all end up with an IIS error when I try to run the Visual Studio project:
HTTP Error 404.15 - Not Found
The request filtering module is configured to deny a request where the query string is too long.
This is what the URL looks like in the IIS Error Page:
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%2525252525252525252525252FAc count%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
As you can tell I get an infinite redirect loop, and this is probably the reason why I'm unable to get this working. I do however have no idea what is causing it. Any help is greatly appreciated.
Guess I'm able to answer my own question as I've just got it working. Might come in handy for people who experience similar errors in the future.
Solution: I had to comment out the following code in 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/42082.html上一篇: 为什么我的查询字符串很长?