ConnectionString configSource not found when deployed to Azure

喜欢而已 提交于 2019-12-23 11:41:13

问题


I am securing my MVC5 project, by moving the connection strings out of web.config into an external file, and not checking this into source control, nor adding it to the project.

My web.config looks like

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

This works perfectly in development.

I have the website hosted in Azure WebSites, and I have manually defined the connectionstrings in the configuration portal.

The problem is that when I publish to Azure, I get the error "Unable to open configSource file 'ConnectionStrings.config'."

Is there a way to override the Connection Strings element in the web.config so it will not try and find the external file? Is Web Transforms able to do this?

Thanks in advance, all help appreciated


回答1:


Use a RemoveAttributes transform on the web.config and remove the configSource attribute on deploy to Azure.




回答2:


This is what I do:

<connectionStrings>
<add name="Entities" connectionString="" providerName="System.Data.EntityClient" />
</connectionStrings>

I use EF, so it expects that; if you have name = "myConnection" then that is what will be reflected above; connectionString="" can remain blank;

Then in azure -> Config, under Connection String, for Name I have Entities for Value I have my EF connection string.

Azure will over-write your web.config as long as you match the Name; does that make sense?

After messing around with this... this may seem like a workaround... strip out the connection string value from ConnectionStrings.config, then check it in commit and push, then add it to your ignore list (gitignore) commit and push., that should stop the errors from showing up since the file now exists; it doesn't have your sensitive data., and now the config values should propagate to the config - Im sure uve thought of this already but this seems like the simplest workaround.



来源:https://stackoverflow.com/questions/27715083/connectionstring-configsource-not-found-when-deployed-to-azure

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!