我有一个新的MVC项目,它使用来自TokenClient的IdentityModel
var tokenClient = new TokenClient(tokenUrl, clientId, CLIENT_SECRET, null, AuthenticationStyle.BasicAuthentication);我为IdentityModel提供了nuget包,一切都很好。但是,在运行时,我会得到以下错误。
方法:'Void IdentityModel.Client.TokenClient..ctor(System.String,System.String,System.String,System.Net.Http.HttpMessageHandler,IdentityModel.Client.AuthenticationStyle‘。
MVC项目的.NET版本为4.6.1
是什么导致了这个问题?我一直在搜索谷歌,找不到任何有帮助的东西。这一定是我错过的一些简单的东西。
编辑:
通过显式声明参数来初始化它也不起作用。
var tokenClient = new TokenClient(tokenUrl, clientId: clientId, clientSecret: CLIENT_SECRET);// CLIENT_SECRET, null, AuthenticationStyle.BasicAuthentication);但是,用一个参数初始化它很好。
var tokenClient = new TokenClient(tokenUrl);发布于 2018-11-20 17:10:20
IdentityModel是由Identity Server的创建者构建的第三方库。v3.10.1确实包含该方法重载。我重新创建了您的错误,而您获得错误的原因是IdentityModel v3.10.1与.NET Framework4.6.1不兼容。创建者更改了该重载的签名,并将HttpMessageHandler作为一个可选参数,以便您的代码能够编译,但在运行时抛出此方法时不会发现错误。您所引用的IdentityModel项目已经由Identity Server的人员存档,所以如果可以的话,我建议您迁移。
在我看来,你有几个选择:
1)迁移到.NET核心,并利用IdentityModel v2。
2)将项目降级为.NET Framework4.5.2( IdentityModel V1的最后兼容版本)
3)不要使用此重载(因为您已经发现单个tokenUrl param有效)。我将远离这种方法,因为您可能会遇到额外的兼容性问题。
基本上,如果您不想迁移到.NET核心,请将该项目保持在4.5.2上。如果你能迁移,那就去做吧。身份服务器正作为一个整体向.NET核心移动,现在通过实现这个飞跃,您将获得更多的里程。
发布于 2018-11-23 13:33:15
我在使用IdentityServer3的MVC入门示例时遇到了同样的问题。如果检查IdentityModel v3.10.1的依赖项,就会注意到它依赖于System.Net.Http (>= 4.3.3)。我的项目有V4.2,更新到当前版本解决了问题。
发布于 2019-08-08 12:09:55
如果您正在使用"System.Net.Http“MVC应用程序,请检查web.config中web.config的绑定重定向。
应该就像
<dependentAssembly>
<assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.0.0.0" />
</dependentAssembly>https://stackoverflow.com/questions/53396295
复制相似问题