问题描述
在尝试启用 owin & 后AspNet Identity 到我的 Web Api 项目(在 VS 2013 + .Net 4.5.1 中)我在每个有效或无效(请求不存在控制器)请求中收到以下错误:
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>
当我在调试模式下检查时,也没有处理异常!我还意识到 Startup
类中的 Configuration
永远不会被调用(实际上从未被调试器捕获).这是启动代码:
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);
}
}
}
推荐答案
我终于找到问题了!在与新创建的项目逐行比较并发现没有区别后,我检查了两个项目的引用,是的!...所有问题都来自缺少包:
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
我不知道为什么在包安装阶段错过了这个打包,但奇怪的是为什么没有抛出任何构建异常?或者没有任何dll引用错误?
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?
这篇关于没有 OWIN 身份验证管理器与请求相关联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!