The "No OWIN Authentication manager associated with this request" workaround appears after ASP. NET WEBAPI Integrated OWIN architecture

Source: Internet
Author: User
Tags stack trace

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.