Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No OWIN authentication manager is associated with the request

After trying to enable owin & AspNet Identity to my Web Api project (in VS 2013 + .Net 4.5.1) I get the following error in each valid or unvalid(request to none exist controller) requests :

<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> 

As I checked in debug mode, no exception is handled too! Also I realized that Configuration in Startup class is never called (indeed never caught by the debugger). here is the code for startup :

[assembly: OwinStartup(typeof(bloob.bloob.Startup))]  namespace bloob.bloob {     public partial class Startup     {         public void Configuration(IAppBuilder app)         {             ConfigureAuth(app);         }     } } 
like image 912
Mahmoud Moravej Avatar asked Jan 13 '14 10:01

Mahmoud Moravej


People also ask

What is Owin authentication?

OWIN (Open Web Interface for . NET) defines a standard interface between . NET Web applications and Web servers, which is used for decoupling server and application. Here we mainly use its feature of authentication. Create WebAPI token-based project Step by Step.

What is Owin in Web API?

Open Web Interface for . NET (OWIN) defines an abstraction between . NET web servers and web applications. OWIN decouples the web application from the server, which makes OWIN ideal for self-hosting a web application in your own process, outside of IIS.


2 Answers

I found the problem finally! After comparing line by line with a newly created project and finding no difference , I checked references on both projects and yes!... All the problem was from missing package :

Microsoft.Owin.Host.SystemWeb 

I don't know why this packaged is missed in package installation phase but the strange point is that why didn't any build exception thrown? or no any dll reference error?

like image 183
Mahmoud Moravej Avatar answered Oct 14 '22 14:10

Mahmoud Moravej


I originally created the project with authentication, but then decided to disable it. I had to remove this in the WebApiConfig.cs file. Make sure you have this if you intend to enable authentication.

        // Web API configuration and services         // Configure Web API to use only bearer token authentication.         config.SuppressDefaultHostAuthentication();         config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType)); 
like image 36
cal5barton Avatar answered Oct 14 '22 13:10

cal5barton