没有OWIN身份验证管理器与请求关联

问题描述 投票:65回答:6

[尝试在我的Web Api项目中启用owin和AspNet身份验证后(在VS 2013 + .Net 4.5.1中,我在每个有效或无效(对不存在的控制器的请求)请求中收到以下错误:

<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);
        }
    }
}
asp.net-mvc-5 owin windows-authentication
6个回答
92
投票

我最初是使用身份验证创建该项目的,但是后来决定禁用它。我必须在WebApiConfig.cs文件中删除它。如果要启用身份验证,请确保具有此名称。


91
投票

我终于找到了问题!在逐行比较一个新创建的项目并没有发现任何差异之后,我检查了两个项目的引用,是的!...所有问题都来自缺少软件包:


8
投票

我的情况,由于web.config中的此设置,它失败了。希望这可以帮助某人避免它。


4
投票

我有同样的问题。该软件包未出现在NuGet软件包管理器中。我在packages.config中添加了参考:


3
投票

如果您实际上不需要OWIN,则只需将其卸载即可。


1
投票

在Web.config中将owin:AutomaticAppStartup键更改为true,这已为我解决,即从以下位置更改:

© www.soinside.com 2019 - 2024. All rights reserved.