【问题标题】:Using ConfigurationManager to access App.config in a v3.5 Azure WebJob在 v3.5 Azure WebJob 中使用 ConfigurationManager 访问 App.config
【发布时间】:2016-04-05 09:23:51
【问题描述】:

问题:ConfigurationManager 无法在 v3.5 Azure WebJob 中访问 App.config

问题:我怎样才能让它工作?

* 背景 *

我继承了一个非常古老的 Web 应用程序,它必须在 .Net 3.5 应用程序池下作为 Windows Azure Web 应用程序运行。

有一个相应的服务必须变成一个Azure WebJob(运行几个小时并且需要访问网站文件)。

我的问题是 WebJob 必须是 .Net v3.5 应用程序才能在相应的 Web 应用程序中运行(它们都共享同一个应用程序池,因此无法将 v4.5 Web 作业部署到 v3.5网络应用程序)。

这意味着我不能使用正常的 WebJob NuGet 包,例如 Windows Azure 配置管理器,我理解它允许 System.Configuration.ConfigurationManager 类以正常方式访问 App.config,允许加载包含基于 EDMX 的 EntityFramework ObjectContexts 的引用库它们的连接字符串和应用程序设置可以通过各种代码访问。代码在 Web 应用程序和 Web 作业之间共享,因此我需要一种在两者之间保持一致的配置方法。

将 WebJob 作为 v4.5 运行允许它使用 ConfigurationManager 正常工作,但一旦我切换到 v3.5(我必须这样做才能使 Web 应用程序工作),我必须删除所有不兼容的 WebJob Nuget包,包括 Windows Azure 配置管理器。 ConfigurationManager 将不再加载 AppSettings,没有错误,它只是不返回任何 AppSettings。

我的问题是 - 如何让 ConfigurationManager 加载已部署的 App.config 而不使用那些不兼容的 NuGet 包。我查看了 Microsoft.WindowsAzure.Configuration.dll 中的代码,但看不出它是如何使 ConfigurationManager 实际工作的,我一定是找错地方了。

【问题讨论】:

    标签: c# azure .net-3.5 azure-webjobs configurationmanager


    【解决方案1】:

    在运行一些 v4.6 和 v3.5 应用程序池测试后(完全相同的代码库 - 除了 Azure WebJobs Publish 之外没有安装 NuGet 包)我发现在 v3.5 应用程序池中运行的 Web 作业根本无法加载他们的配置文件。

    附带说明 RSACryptoServiceProvider.ImportParameters 在 v3.5 下也会爆炸。

    以下工作强制加载配置文件。

    class Program
    {
        static void Main()
        {
            AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", @"D:\home\site\wwwroot\App_Data\jobs\triggered\DataImportWebJob\[TheAppName].exe.config");
    

    感谢Using ConfigurationManager to load config from an arbitrary location

    【讨论】:

      猜你喜欢
      • 2010-10-09
      • 1970-01-01
      • 2011-02-17
      • 1970-01-01
      • 2013-01-09
      • 2010-11-19
      • 1970-01-01
      • 2016-01-07
      • 2019-06-21
      相关资源
      最近更新 更多