我正在使用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?
答案 0 :(得分:0)
您可以参考类似的SO thread并使用以下步骤。
1。发布项目后,选择Configure
标签。
2。从所有连接字符串中取消选中use this connection string at runtime
。
3。单击Save
,然后尝试再次publish
网站。