在尝试使用谷歌在外部身份验证,应用程序给了我以下异常:序列包含多个元素Microsoft.Owin.Security.AuthenticationManager
<错误> <消息>发生了错误。 <ExceptionMessage>序列包含一个以上的元件</ExceptionMessage > <ExceptionType> System.InvalidOperationException </ExceptionType > <堆栈跟踪> 在System.Linq.Enumerable.SingleOrDefault [TSource](IEnumerable的
1 source) at Microsoft.Owin.Security.AuthenticationManager.<AuthenticateAsync>d__8.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()在System.Web.Http.HostAuthenticationFilter.d__0.MoveNext()---从以前位置抛出异常的堆栈跟踪结束---在System.Runtime.CompilerServices的System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务) System.Runtime.CompilerService上的.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务) s.TaskAwaiter.GetResult()在System.Web.Http.Controllers.AuthenticationFilterResult.d__0.MoveNext()---从以前的位置抛出异常的堆栈跟踪结束---在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.Dispatcher.HttpControllerDispatcher.d__1.MoveNext()
我已经配置我的网络API的OAuth如下:
public void ConfigureOAuth(IAppBuilder app)
{
app.UseExternalSignInCookie(
Microsoft.AspNet.Identity.DefaultAuthenticationTypes.ExternalCookie);
OAuthBearerOptions = new OAuthBearerAuthenticationOptions();
OAuthAuthorizationServerOptions OAuthServerOptions =
new OAuthAuthorizationServerOptions()
{
AllowInsecureHttp = true,
TokenEndpointPath = new PathString("/token"),
AccessTokenExpireTimeSpan = TimeSpan.FromMinutes(30),
Provider = new SimpleAuthorizationServerProvider(),
};
app.UseOAuthAuthorizationServer(OAuthServerOptions);
app.UseOAuthBearerAuthentication(OAuthBearerOptions);
googleAuthOptions = new GoogleOAuth2AuthenticationOptions()
{
ClientId = ClientId,
ClientSecret = ClientSecret,
Provider = new GoogleAuthProvider()
};
app.UseGoogleAuthentication(googleAuthOptions);
}
我发现解决方案[这里](http://stackoverflow.com/questions/24978940/webapi-oauth-useoauthbearerauthentication-gives-sequence-contains-more-than-one)它会帮助你 – 2016-02-17 04:39:21