发布时Azure webapp连接字符串不起作用

时间:2019-09-10 07:41:35

标签: entity-framework azure azure-web-app-service

我正在使用ASP.NET Framework Web App。出于安全原因等原因,我决定将connectionStrings从默认的web.config文件移至外部文件。 web.config和外部文件与configSource属性链接在一起。

当我在本地调试应用程序时,此方法工作正常。但是,当我尝试发布应用程序时,出现错误消息:“'Entities-Web.config连接字符串'参数不能为null或为空。”

对于外部文件,我已将“构建操作”设置为“内容”,并将“复制到输出目录”设置为“始终复制”。

这是在我的web.config文件中:

  <connectionStrings configSource="ConnectionStrings.config">
  </connectionStrings>

这是ConnectionStrings.config文件:

<?xml version="1.0" encoding="utf-8"?>
  <connectionStrings>
    <add name="Entities" connectionString="somestring" providerName="System.Data.EntityClient" />
  </connectionStrings>

如何使发布时正确加载connectionStrings?

1 个答案:

答案 0 :(得分:0)

您可以参考类似的SO thread并使用以下步骤。

1。发布项目后,选择Configure标签。

enter image description here

2。从所有连接字符串中取消选中use this connection string at runtime

enter image description here

3。单击Save,然后尝试再次publish网站。