0

我在我们的网站中实现了 Google 身份验证,其中客户端是 Angular,后端是 IIS 上的 .NET C#。我在客户端启动该过程并获得访问令牌。令牌必须转发到基于 .NET 的后端。在后端,我将 Google.Apis.Auth 1.51.0 库称为 NuGet 包。我使用那里的工具验证令牌。在 Visual Studio 调试模式下从源代码测试时,它可以完美运行,但在我发布版本后无法在 IIS 下运行。

错误消息是:“无法加载文件或程序集 'Google.Apis.Auth, Version=1.51.0.0, Culture=neutral, PublicKeyToken=4b01fa6e34db77ab'。”

我检查了依赖项,它们位于具有正确版本的本地文件夹中。(Google.Apis.dll、Google.Apis.Core.dll、Google.Apis.Auth.dll、Google.Apis.Auth.PlatformServices.dll 和 Newtonsoft.Json.dll)一般的解决方案是使用 bindingRedirect。我尝试在web.config中将0.0.0.0-1.51.0.0范围设置为新版本1.51.0.0,但是没有效果。像这样:

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentAssembly>
            <assemblyIdentity name="Google.Apis.Auth" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-1.51.0.0" newVersion="1.51.0.0" />
      </dependentAssembly>
    </assemblyBinding>
</runtime>

我尝试使用 Google.Apis、Google.Apis.Core 和 Google.Apis.Auth.PlatformServices 执行此操作,但没有成功。我在配置标签中没有命名空间。我在有和没有 publicKeyToken 的情况下都试过了。

我想问一下你有没有遇到过这个问题?你知道该怎么做吗?我非常感谢您的帮助。

4

2 回答 2

0

我在我们的大项目中遇到了同样的问题。Google nuget 引用在库中,并且该库正在动态加载。我尝试了几种加载 google dll 的方法,但我无法完成。

之后,我在主项目中添加了 google api 、 storage 等引用,现在它可以正常工作了。

于 2021-07-29T06:46:20.477 回答
0

最后我们发现了问题。我们使用了一个自动发布过程来创建一个安装包。不幸的是,此工具排除了 *.deps.json 文件,该文件必须包含才能使用此 Google dll。包含此文件后,IIS 可以加载 dll。

于 2021-06-18T13:53:59.807 回答