在尝试为我的Web项目(在VS2013+ .Net 4.5.1中)启用owin & AspNet标识后,我在每个有效或无效(对无存在控制器的请求)请求中得到以下错误:
<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>
当我在调试模式中检查时,也没有异常被处理!我还意识到Startup
类中的Configuration
从未被调用过(实际上从未被调试器捕获过)。以下是启动代码:
[assembly: OwinStartup(typeof(bloob.bloob.Startup))]
namespace bloob.bloob
{
public partial class Startup
{
public void Configuration(IAppBuilder app)
{
ConfigureAuth(app);
}
}
}
发布于 2014-01-14 00:16:30
我终于找到问题所在了!在与新创建的项目逐行比较后,发现没有差异,我检查了两个项目的引用,是的!所有的问题都来自于缺少包:
Microsoft.Owin.Host.SystemWeb
我不知道为什么在包安装阶段遗漏了这个包,但奇怪的是为什么没有抛出任何构建异常?或者没有任何dll引用错误?
发布于 2015-05-15 08:44:15
我最初创建了带身份验证的项目,但后来决定禁用它。我不得不将其从WebApiConfig.cs
文件中删除。如果您打算启用身份验证,请确保具有此权限。
// Web API configuration and services
// Configure Web API to use only bearer token authentication.
config.SuppressDefaultHostAuthentication();
config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType));
发布于 2016-05-06 16:44:24
我的情况是,由于web.config中的此设置,它失败了。希望这能帮助某些人避免这种情况。
<appSettings>
<add key="owin:AutomaticAppStartup" value="false" />
</appSettings>
https://stackoverflow.com/questions/21089196
复制相似问题