After you open the Owin module in the ASP. NET WebApi project, if you do not configure the authentication method in the startup class of Owin, the associated controller and action calling WEBAPI will have the following exception:
An error occurred. There is no OWIN Authentication manager associated with this request. ExceptionType:System.InvalidOperationExceptionStackTrace: in System.Web.Http.Owin.PassiveAuthenticationMessageHandler.SuppressDefaultAuthenticationChallenges ( Httprequestmessage request) at System.web.http.owin.passiveauthenticationmessagehandler.<sendasync>d__0. MoveNext ()---the end of the stack trace in the previous location that threw the exception---in System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (Task Task) in the System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (Task Task) in System.web.http.httpserver.<sendasync>d__0.movenext ()
If the English version of the VisualStudio, the above exception information will be: No OWIN authentication Manager is associated with the request
The reason is because we used the Owin framework in the ASP. Webapi project, but did not specify the authentication method used by the Owin framework, and WEBAPI also enabled authentication by default, so Webapi could not authenticate the incoming HTTP request and throw an exception.
We can see that the configuration method for the Owin framework startup class below is empty and there is no identity authentication method for Owin.
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingMicrosoft.owin;usingMicrosoft.Owin.Security;usingMicrosoft.Owin.Security.Cookies;usingOwin; [Assembly:owinstartup (typeof(Daimler.CdnMgmt.Web.Startup))]namespacedaimler.cdnmgmt.web{ Public Partial classStartup { Public voidConfiguration (Iappbuilder app) {}}}
There are two solutions:
First: Specify the default authentication method in the startup class of Owin.
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingMicrosoft.owin;usingMicrosoft.Owin.Security;usingMicrosoft.Owin.Security.Cookies;usingOwin; [Assembly:owinstartup (typeof(Daimler.CdnMgmt.Web.Startup))]namespacedaimler.cdnmgmt.web{ Public Partial classStartup { Public voidConfiguration (Iappbuilder app) {app. Setdefaultsigninasauthenticationtype (Cookieauthenticationdefaults.authenticationtype); App. Usecookieauthentication (Newcookieauthenticationoptions ()); } }}
The "No OWIN Authentication manager associated with this request" workaround appears after ASP. NET WEBAPI Integrated OWIN architecture