새로운 Asp.Net MVC5 프로젝트는 로그인 페이지에 무한 루프를 생성합니다.
Visual Studio 2013을 사용하여 새로운 프로젝트를 만들고 있으며 Asp.Net MVC와 프레임 워크 4.5.1을 선택합니다. 프로젝트가 생성되고 F5 외에는 아무것도하지 않고 기본 웹 페이지를 시작합니다. 불행히도 로그인 페이지로 리디렉션되는 로그인 페이지로 리디렉션됩니다. 다음은 브라우저에있는 URL의 짧은 버전입니다.
http://localhost:5285/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%252525252525
이벤트 뷰어에 오류가 없습니다. 그러나 화면에서 나는 다음을 본다.
"HTTP 오류 404.15-찾을 수 없음 요청 필터링 모듈이 쿼리 문자열이 너무 긴 요청을 거부하도록 구성되었습니다."
웹 사이트는 IIS Express의 기본 설정으로 실행됩니다. 이 문제를 어떻게 해결할 수 있습니까? 내 Visual Studio 2013에 문제가 있다고 생각합니까?
편집하다
새로운 웹 사이트를 만들고 IIS에서 호스팅하면 작동합니다. 그러나 새 웹 사이트를 만들고 (아무것도 수정하지 않고) 재생 (기본적으로 IIS Express 시작) 만 누르면 그렇지 않습니다.
편집 2
Documents \ IISExpress \ config \ applicationhost.config에서 모든 웹 사이트 를 삭제했습니다 . 모든 것을 다시 컴파일했고 다음 항목을 만들었습니다.
<siteDefaults>
<logFile logFormat="W3C" directory="%IIS_USER_HOME%\Logs" />
<traceFailedRequestsLogging directory="%IIS_USER_HOME%\TraceLogFiles" enabled="true" maxLogFileSizeKB="1024" />
</siteDefaults>
<applicationDefaults applicationPool="Clr4IntegratedAppPool" />
<virtualDirectoryDefaults allowSubDirConfig="true" />
</sites>
IIS가 아닌 IIS Express에서 여전히 오류가 발생합니다.
Visual Studio에서 프로젝트 강조
오른쪽의 '속성'패널을 열거 나 F4를 누릅니다.
'Windows 인증'을 '사용 안함'으로 설정하십시오.
'익명 인증'을 '사용'으로 설정하십시오.
이 문제는 MVC 5 템플릿에서 선택한 인증 모드 (기본적으로)로 인해 올바르게 구성되지 않은 경우 무한 루프로 이어질 수있는 리디렉션의 ReturnUrl 스타일을 트리거합니다.
OWIN 시작 검색을 비활성화하려면이 키를 webconfig 파일에 추가하십시오.
<add key="owin:AutomaticAppStartup" value="false"/>
[AllowAnonymous]
로그인 작업에 대한 속성 이 없습니다 .
[AllowAnonymous]
public ActionResult Login(string returnUrl)
{
// code....
}
두 번째 가능성 은 IIS Express에만 해당됩니다. 동일한 기본 WebApplication1
프로젝트를 여러 번 만들고 다른 인증 설정을 사용하는 경우 IIS Express는 구성 파일에 추가 인증 설정을 저장했습니다. 다음과 같은 것 :
<location path="WebApplication1">
<system.webServer>
<security>
<authentication>
<windowsAuthentication enabled="true" />
<anonymousAuthentication enabled="false" />
</authentication>
</security>
</system.webServer>
</location>
</configuration>
구성은 사용자의 문서 폴더 Documents\IISExpress\config\
에 있으며 다음을 찾아야합니다.
applicationhost.config
그런 다음 <location path="WebApplication1">
위에서 언급 한 xml 노드를 삭제하십시오 .
VS 2015+ 업데이트
Visual Studio 2015 이상을 사용하는 경우 다음 경로에서 구성 파일을 확인하세요. $(solutionDir)\.vs\config\applicationhost.config
각 솔루션에는 자체 구성 파일이 있습니다.
( 소스 링크 ) 를 제거해야했습니다 .
<authorization>
<deny users="?" />
</authorization>
나는 내가 늦을 수도 있다는 것을 알고 있으며 이것은 OP의 질문에 대한 직접적인 것이 아닙니다. 그러나 미래에 누군가가 여기에 오면 한 가지 더 확인 AllowAnonymous
하고 Authorize
속성은 모든 하위 작업 도 확인해야한다는 것 입니다.
예를 들어, 이동 경로와 사이드 바에 대해 2 개의 하위 작업을 호출하는 레이아웃 (로그인 페이지에서도 사용)이 AllowAnonymous
있었지만 Authorize
속성 이 없었습니다 (컨트롤러에 속성이 있음).
이 도움을 바랍니다.
IIS에서 웹 사이트를 선택하고 인증을 확인하십시오. 양식 인증을 사용하는 경우-
- 'Windows 인증'을 '사용 안함'으로 설정하십시오.
- '익명 인증'을 '사용'으로 설정하십시오.
- '양식 인증'을 '사용'으로 설정하십시오.
MVC 프로젝트가 .Net 4.5 용으로 구성 되었기 때문에 동일한 문제에 직면했지만 IIS의 응용 프로그램 풀로 .Net 4.0을 사용하고있었습니다. .Net 4.5 응용 프로그램 풀로 전환하고 문제가 수정되었습니다. 이것이 다른 사람에게 도움이되기를 바랍니다!
TL : DR? ~ / Account / Login과 같은 인증 페이지에서 보호 된 웹 API (인증이 필요한 모든 웹 API)를 호출하지 마십시오 (그 자체로는이를 수행하지 않음). 그렇게하면 서버 측에서 무한 리디렉션 루프에 들어갑니다.
원인
나는 범인이 간접적이고, 발견 AccountController::Authorize
과 사실 AccountController
들로 장식되어 있습니다 [Authorize]
.
근본 원인은 "보호 된 웹 API"에 액세스하는 HomeViewModel () (home.viewmodel.js의 6 행)에서 호출 된 Sammy ()였습니다. 이것은 / Account / Login에 대해 수행되었으며, 그 결과 / Account / Login이 자체로 리디렉션되었습니다.
확인
여러 가지 방법을 통해 이것이 문제의 원인임을 확인할 수 있습니다.
- 장식
AccountController::Authorize
으로[AllowAnonymous]
- 뷰 모델 생성 중에 만들어진 Sammy () 호출을 주석 처리하십시오.
해결책
해결책은 이미 승인이 필요한 뷰에 대해서만 앱 번들 (일명 "~ / bundles / app")을 내보내는 것이 었습니다. 내가 아는 한 / Account / 뷰는 클래식 MVC 기반 뷰이며 앱 데이터 모델 / 뷰 모델의 일부가 아니지만 실수로 번들 Scripts.Render(@"~/bundles/app")
호출을 _Layout.cshtml 로 옮겼습니다 (모든 MVC 뷰에 대해 보호 된 웹 API 호출이 발생하도록 함). , / Account / 포함.)
ASP.Net MVC 5 템플릿은 Microsoft.Owin 및 관련 라이브러리를 프로젝트에 추가합니다. Owin 인프라에는 양식 인증이 필요하지 않으므로 템플릿은 web.config에 다음 키도 도입합니다.
<system.webServer>
<modules>
<remove name="FormsAuthentication" />
</modules>
</system.webServer>
이 키가 있으면 로그인 페이지로 원치 않는 루프백이 발생할 수 있습니다. 댓글을 달면 일부 사람들의 문제를 해결하는 데 도움이 될 수 있습니다.
제 경우에는 : 내 _layout.cshtml에서 Html.Action을 사용하여 Authorize Controller에서 Action을 호출합니다. 예 : Html.Action ( "Count", "Product")-> 루프 오류
수정 : 해당 작업에서 [AllowAnonymous] 속성으로 장식 (또는 _layout에서 이러한 Html 도우미 제거)
이 문제를 몇 시간 동안 처리했습니다.
저에게는 Startup.Auth.cs 파일에있었습니다.
이 코드는 주석 처리되었을 때 리디렉션 루프를 중지했습니다.
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login")
});
Please be aware that this is potentially harmful advice, it's rarely a good idea to modify an applicationhost config file directly, there are usually tools that will do this for you, safely (for example, from within Visual Studio.) Before proceeding, be sure to create a backup copy of this file in the event your IIS Express becomes trashed.
To fix this problem, I took the default IIS configuration file located here :
C:\Windows\System32\inetsrv\config\applicationHost.config
To my document
%userprofile%\documents\iisexpress\config\applicationhost.config
And it worked.
This was because I had some Windows Authentification set and not the anonymous account.
Make sure you have no actions in pipeline that have authorize attribute. In my case, my layout had navigation menu controller which was missing allowAnonymous attribute.
I solved the same problem thanks to this accepted answer: ASP.NET Login Redirect Loop when user not in role.
It is possible that the controller containing Login action is decorated with an AuthorizeAttribute
(even a custom one) while the login action is not decorated with AllowAnonymous
attribute. Removing AuthorizeAttribute
from the controller and adding AllowAnonymous
to login action may be a possible solution.
These answers are more or less pieces of the same puzzle; I'll try to put everything in one place. Problem that OP described hit my application the moment I implemented the OWIN pipeline and AspNET Identity.
So let's see how to fix it...
- OWIN Startup
I guess you need it, because if you don't, then you don't need authentication, and I guess you do. Except it you're using some old-style authentication, and I guess you don't. So, don't remove either the OWIN startup attribute...
[assembly: OwinStartupAttribute(typeof(YourApp.Probably_App_Start.SomethingLikeAuthConfig))]
...or the configuration line...
<add key="owin:AppStartup" value="YourApp.Probably_App_Start.SomethingLikeAuthConfig" />
- Access restriction on controllers
Now we cleared this up, you need the authentication. This means either each of your controller needs the [Authorize]
attribute, or you can do the same to all controllers in one place by registering the thing globally (e.g. in RegisterGlobalFilters()
, add line filter.Add(new AuthorizeAttribute())
). In the former case (when securing each controller separately) skip this part, just go to the next one. In the latter case all of your controllers will be secured against unauthorized acces, so you need an entry point for that authorization - unprotected Login()
action. Just add...
[AllowAnonymous]
...and you should be good.
- OWIN cookie configuration
When your user logs in, his browser stores encrypted (hopefully!) cookie in order to simplify things for the system. So, you need cookie - don't delete the line that says UseCookieAuthentication
.
- What you really have to do is turn off the IIS integrated authentication mechanism for your web application. This means switching off
Windows Authentication
(Disabled) and enable letting any user in, at least as long as IIS Express is now concerned, by settingAnonymous Authentication
(Enabled).
When you start your web site, this will in turn copy these settings into IIS Express configuration (applicationhost.config
), and there you should see these two lines:
<windowsAuthentication enabled="false" />
<anonymousAuthentication enabled="true" />
You might have the authorization config in your web.config that says
deny users="?"
. It means the authorization subsystem is instructed to prevent anonymous users from entering. With OWIN, this still works as designed. You either have to remove this, or make your anonymous user able to access the Login page by using something like...<location path="Account/Login"> <system.web> <authorization> <allow users="*" /> </authorization> </system.web> </location>
HTH
I had similar issues where it was in an infinite loop when calling back to the website locally. It turns out that when debugging locally it was redirecting the ports. I updated port numbers in the project properties screen but left the Azure definition the same in the cloud project and everything started to work as expected.
I had the same issue with my Asp.Net MVC 4 project. I resolved it by going to Startup.cs and commenting out the line for ConfigureAuth(app)
public void Configuration(IAppBuilder app)
{
//ConfigureAuth(app);
}
I also made sure that I had Windows Authentication enabled in IIS for my project, and all other authentication options disabled.
For me, this turned out to be caused by my LoginViewModel containing references to translation resources files, apparently being protected by authentication. I removed those references, and the problem was solved.
For me, removing the following block fixed it:
<authorization>
<deny users="?" />
<allow users="*" />
</authorization>
Assume
<authentication mode="None" />
in my case it was a very wired problem , i decorated the home controller by non existent role. so it causes a redirection loop.
Go to to your applicationhost.config file and set anonymousauthentication = "true"
<authentication>
<anonymousAuthentication enabled="true" userName="" />
<windowsAuthentication enabled="true">
<providers>
<add value="Negotiate" />
<add value="NTLM" />
</providers>
</windowsAuthentication>
</authentication>
'Program Tip' 카테고리의 다른 글
정기적으로 실행되도록 작업을 예약하려면 어떻게합니까? (0) | 2020.10.23 |
---|---|
주어진 인덱스에 존재하는 경우 ArrayList 대체 요소? (0) | 2020.10.23 |
redis로 지속성을 비활성화하는 방법은 무엇입니까? (0) | 2020.10.23 |
해결 방법“문자열 보간은 선택적 값에 대한 디버그 설명을 생성합니다. (0) | 2020.10.23 |
jQuery UI 슬라이더 (프로그래밍 방식으로 설정) (0) | 2020.10.23 |