【问题标题】:How to deploy Google Admin SDK to Azure cloud service如何将 Google Admin SDK 部署到 Azure 云服务
【发布时间】:2018-06-24 13:59:07
【问题描述】:

按照 ASP.NET MVC 示例 here,我在我的 Web 应用程序中实现了 Google Admin SDK,以便我可以使用目录服务获取与组织单位关联的组织单位和/或用户的列表。

在本地一切正常(身份验证回调有效,因为我利用ngrok 来访问我的本地框),但是当我部署到 MS Azure 中的云服务时,应用程序无法启动,并且我看到以下错误在事件日志中:

无法创建角色入口点:System.TypeLoadException:由于以下异常,无法加载角色入口点: -- System.IO.FileLoadException:无法加载文件或程序集“System.Web.Mvc,版本=4.0.0.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35”或其依赖项之一。找到的程序集的清单定义与程序集引用不匹配。 (来自 HRESULT 的异常:0x80131040) 文件名:'System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'

我在我的 .NET 4.5 Web 应用程序中使用 ASP.NET MVC 版本 5.2.3,并在我的 web.config 中使用以下设置。我不清楚这个明确的引用来自版本 4.0.0.0 的确切位置,但我已经重新部署了我的应用程序,有和没有对 Google API 库的引用,以及错误 当我引用 Google API 库时肯定会发生。

<dependentAssembly>
    <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
</dependentAssembly>

最初几次出现错误时,我认为是因为我在 AppFlowMetadata 类中使用了 FileDataStore 对象,并且本地文件存储在 Azure 云服务中可能不可用。所以找到this SO post,我创建了自己的数据库存储,它实现了 IDataStore 接口,并且在本地也很好用,但是部署到 Azure 会导致与上面列出的相同的错误。

有谁知道 Azure 部署失败的原因以及引用 System.Web.MVC Version=4.0.0.0 的原因/位置?

public class AppFlowMetadata : FlowMetadata
    {
        public AppFlowMetadata()
        {
        }

    private static readonly IAuthorizationCodeFlow flow =
    new GoogleAuthorizationCodeFlow(new GoogleAuthorizationCodeFlow.Initializer
    {
        ClientSecrets = new ClientSecrets
        {
            ClientId = "CLIENT-ID",
            ClientSecret = "CLIENT-SECRET"
        },
        Scopes = new[] { DirectoryService.Scope.AdminDirectoryOrgunit, DirectoryService.Scope.AdminDirectoryUser },
        DataStore = new GoogleDBDataStore()
    });

    public override string GetUserId(Controller controller)
    {
        var user = controller.Session["user"] as USER;

        if (user != null)
        {
            return user.UserID.ToString();
        }
        else
        {
            return null;
        }
    }

    public override IAuthorizationCodeFlow Flow
    {
        get { return flow; }
    }
}

【问题讨论】:

    标签: c# azure google-api google-admin-sdk google-api-dotnet-client


    【解决方案1】:

    有谁知道 Azure 部署失败的原因以及引用 System.Web.MVC Version=4.0.0.0 的原因/位置?

    您可以从这个blog 得到答案。它详细阐述了根本原因和解决方案。以下是博客中的sn-p。

    解决方案:

    1) 打开项目 bin 文件夹中的 .dll.config。

    2) 检查是否有您需要的 BindingRedirect 条目。如果没有,请遵循以下两个选项之一:

    • 复制 web.config 或 app.config 内容(考虑以下之一 这两个配置文件包含您需要的信息)和 将其粘贴到 .dll.config 文件中。

    • 手动创建程序集绑定条目:

    3) 将 .dll.config 文件添加到您的解决方案(与 web.config 或 app.config 相同级别)并将复制到输出目录属性设置为“始终复制”。

    根本原因

    通常,当向您的项目添加新程序集时,Visual Studio 会自动在您的 web.config(Web 角色)或 app.config(工作者角色)中创建 bindingRedirect 条目,以避免错误的程序集版本问题。

    但是,在 Azure 云服务中,来自 web.config 和 app.config 的程序集绑定不起作用,因为 WaIISHost(Web 角色)和 WaWorkerHost(工人角色)无法读取这两个配置文件,相反,他们读取 .dll.config 文件,这是程序集绑定配置需要的文件

    【讨论】:

    • 绑定重定向出现在 #2 中(它看起来就像 web.config),然后是上面的 #3,一切都很好 - 很棒的信息。
    猜你喜欢
    • 2013-08-19
    • 2012-07-15
    • 2014-12-13
    • 1970-01-01
    • 2020-09-22
    • 1970-01-01
    • 2017-06-24
    • 2012-09-05
    • 2018-08-29
    相关资源
    最近更新 更多