No OWIN authentication manager is associated with the request

杀马特。学长 韩版系。学妹 提交于 2019-11-28 04:37:16
cal5barton

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

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?

My case, it failed since this settings in web.config. Hope this helps someone to avoid it.

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

if you don't actually need OWIN you can simply uninstall it.

one way to do it is in Nuget Manager uninstall every OWIN library, the order will be dictated by their dependencies.

after this is done you don't need any OWIN related code or config. this worked out best for me since I am using windows auth.

I had the same problem. The package was not appearing in the NuGet Package manager. I added reference in packages.config:

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

And reference in the project file (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>

Changing the owin:AutomaticAppStartup key to true in Web.config fixed this for me, i.e. change it from:

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

to this:

<appSettings>
    <add key="owin:AutomaticAppStartup" value="true" />
</appSettings>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!