vb.net UseExternalSignInCookie 不是 Owin.IAppBuilder 的成员

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20313164/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 15:59:49  来源:igfitidea点击:

UseExternalSignInCookie is not a member of Owin.IAppBuilder

vb.netasp.net-mvc-5owin

提问by Matt Ruwe

I have two VS 2013 MVC 5 SPA web projects. Both are newly created and have not been modified (i.e. still the vanilla template). One of them works and one does not. The only difference that I can see is that one was created in a project that has been upgraded from VS 2010 to VS 2012 and then to 2013 and is one of about 60-70 projects in the solution. The other is a newly created solution with the MVC app as the only project in it.

我有两个 VS 2013 MVC 5 SPA web 项目。两者都是新创建的并且没有被修改(即仍然是 vanilla 模板)。其中一个有效,一个无效。我能看到的唯一区别是,一个是在从 VS 2010 升级到 VS 2012 再到 2013 的项目中创建的,并且是解决方案中大约 60-70 个项目之一。另一个是新创建的解决方案,其中 MVC 应用程序是其中唯一的项目。

The fresh MVC app in it's own solution works without any problem, however, the MVC app that was added to the upgraded project gives the following compile time error:

新的 MVC 应用程序在它自己的解决方案中工作没有任何问题,但是,添加到升级项目的 MVC 应用程序给出了以下编译时错误:

'UseExternalSignInCookie' is not a member of 'Owin.IAppBuilder'. ...\Mvc5UI\App_Start\Startup.Auth.vb
'UseOAuthBearerTokens' is not a member of 'Owin.IAppBuilder'. ...\Mvc5UI\App_Start\Startup.Auth.vb
'GetExternalAuthenticationTypes' is not a member of 'Microsoft.Owin.Security.IAuthenticationManager'. ...\Mvc5UI\Controllers\AccountController.vb

The code where the problem is (Startup.Auth.vb):

问题所在的代码(Startup.Auth.vb):

Public Sub ConfigureAuth(app As IAppBuilder)
     '...
    app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie)
    app.UseOAuthBearerTokens(OAuthOptions)
    '...
End Sub

and (AccountController.vb)

和 (AccountController.vb)

Public Function GetExternalLogins(returnUrl As String, Optional generateState As Boolean = False) As IEnumerable(Of ExternalLoginViewModel)
    Dim descriptions As IEnumerable(Of AuthenticationDescription) = Authentication.GetExternalAuthenticationTypes()
    '...
End Sub

This code is the same in both the upgraded solution and the newly built solution, so there's something environmental going on. I've made sure that the NuGet packages are setup correctly. The thing that I find most interesting (and is probably a misunderstanding on my part) is that when I explore the assembly metadata for IAppBuilderI don't see any of the methods that are referenced, so the error makes sense. However, then the question becomes, why does it work in the newly created MVC app?

此代码在升级的解决方案和新构建的解决方案中是相同的,因此发生了一些环境问题。我已确保正确设置了 NuGet 包。我发现最有趣的事情(可能是我的误解)是,当我浏览程序集元数据时,IAppBuilder我没有看到任何引用的方法,因此错误是有道理的。然而,那么问题就变成了,为什么它可以在新创建的 MVC 应用程序中工作?

回答by Matt Ruwe

As I was writing the question, I was able to determine the answer. The UseExternalSignInCookieand UseOAuthBearerTokensmethods are actually extension methods on the IAppBuilder, which is why I was confused. These extension methods are found in Microsoft.Owin.Security.Cookies which was apparently not being referenced correctly.

在我写问题的时候,我能够确定答案。该UseExternalSignInCookieUseOAuthBearerTokens方法实际上是对IAppBuilder,这就是为什么我很困惑的扩展方法。这些扩展方法可以在 Microsoft.Owin.Security.Cookies 中找到,但显然没有被正确引用。

After figuring that out and as I was going through the project references, I noticed that the Microsoft.AspNet.Identity.Owin assembly reference was broken, so I reinstalled that package with update-Package -reinstall Microsoft.AspNet.Identity.Owinpackage manager command and then everything started working.

在弄清楚这一点之后,当我浏览项目引用时,我注意到 Microsoft.AspNet.Identity.Owin 程序集引用已损坏,因此我使用update-Package -reinstall Microsoft.AspNet.Identity.Owin包管理器命令重新安装了该包,然后一切开始工作。

I'm still not sure why this was broken to begin with, but it's working now.

我仍然不确定为什么它一开始就被破坏了,但现在它正在起作用。