programing

요청과 관련된 OWIN 인증 관리자가 없습니다.

nasanasas 2020. 11. 19. 21:35
반응형

요청과 관련된 OWIN 인증 관리자가 없습니다.


내 Web Api 프로젝트 (VS 2013 + .Net 4.5.1에서)에 owin 및 AspNet Identity를 활성화하려고 시도한 후 각 유효하거나 유효하지 않은 (존재하지 않는 컨트롤러 요청) 요청에서 다음 오류가 발생합니다.

<Error>
<Message>An error has occurred.</Message>
<ExceptionMessage>
No OWIN authentication manager is associated with the request.
</ExceptionMessage>
<ExceptionType>System.InvalidOperationException</ExceptionType>
<StackTrace>
at System.Web.Http.Owin.PassiveAuthenticationMessageHandler.SuppressDefaultAuthenticationChallenges(HttpRequestMessage request) at System.Web.Http.Owin.PassiveAuthenticationMessageHandler.<SendAsync>d__0.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() at System.Web.Http.HttpServer.<SendAsync>d__0.MoveNext()
</StackTrace>
</Error>

디버그 모드에서 확인 했으므로 예외도 처리되지 않습니다! 또한 나는 것을 깨달았다 Configuration에서 Startup클래스가 호출되지 않습니다 (실제로 디버거에 의해 체포되지 않습니다). 시작 코드는 다음과 같습니다.

[assembly: OwinStartup(typeof(bloob.bloob.Startup))]

namespace bloob.bloob
{
    public partial class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            ConfigureAuth(app);
        }
    }
}

원래 인증으로 프로젝트를 만들었지 만 비활성화하기로 결정했습니다. WebApiConfig.cs파일 에서 이것을 제거해야했습니다 . 인증을 사용하려는 경우이 정보가 있는지 확인하십시오.

        // Web API configuration and services
        // Configure Web API to use only bearer token authentication.
        config.SuppressDefaultHostAuthentication();
        config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType));

마침내 문제를 발견했습니다! 새로 생성 된 프로젝트와 한 줄씩 비교하고 차이가없는 것을 찾은 후 두 프로젝트 모두에 대한 참조를 확인했고 예! ... 모든 문제는 누락 된 패키지에서 발생했습니다.

Microsoft.Owin.Host.SystemWeb

이 패키지가 패키지 설치 단계에서 누락 된 이유를 모르겠지만 이상한 점은 왜 빌드 예외가 발생하지 않았습니까? 또는 dll 참조 오류가 없습니까?


제 경우에는 web.config 의이 설정 이후에 실패했습니다. 이것이 누군가가 그것을 피하는 데 도움이되기를 바랍니다.

<appSettings>
    <add key="owin:AutomaticAppStartup" value="false" />
</appSettings>

나는 같은 문제가 있었다. 패키지가 NuGet 패키지 관리자에 표시되지 않았습니다. packages.config에 참조를 추가했습니다.

 <package id="Microsoft.Owin.Host.SystemWeb" version="2.1.0" targetFramework="net45" />

프로젝트 파일 (xxx.csproj)에서 참조 :

 <Reference Include="Microsoft.Owin.Host.SystemWeb">
  <HintPath>..\packages\Microsoft.Owin.Host.SystemWeb.2.1.0\lib\net45\Microsoft.Owin.Host.SystemWeb.dll</HintPath>
</Reference>

실제로 OWIN이 필요하지 않은 경우 간단히 제거 할 수 있습니다.

이를 수행하는 한 가지 방법은 Nuget Manager에서 모든 OWIN 라이브러리를 제거하는 것입니다. 순서는 종속성에 따라 결정됩니다.

이 작업이 완료되면 OWIN 관련 코드 또는 구성이 필요하지 않습니다. Windows 인증을 사용하고 있기 때문에 이것은 나에게 가장 잘 맞았습니다.


Web.config 에서 owin:AutomaticAppStartup키를 true변경하면 이 문제가 해결되었습니다. 즉, 다음과 같이 변경합니다.

<appSettings>
    <add key="owin:AutomaticAppStartup" value="false" />
</appSettings>

이에:

<appSettings>
    <add key="owin:AutomaticAppStartup" value="true" />
</appSettings>

참고 URL : https://stackoverflow.com/questions/21089196/no-owin-authentication-manager-is-related-with-the-request

반응형