从 ASP.NET 应用程序更改 web.config
我需要更改 web.config 文件中的数据库连接字符串,但不知道如何进行此操作。有人有这方面的经验吗?
更新
抱歉,上面不是很清楚,我希望能够在部署 Web 应用程序后更改连接字符串
I need to change the database connection string in the web.config file but havent got a clue how to go about this. Does anyone have any experience with that?
UPDATE
Sorry, not very clear above, I want to be able to change a connection string from the web application after it has been deployed
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
http://msdn.microsoft.com/en-us /library/system.configuration.configuration.connectionstrings.aspx
编辑:
http://msdn.microsoft.com/en-us/library/system.configuration.connectionstringssection.aspx
另外,正如其他人指出的那样,您需要设置正确的权限,但有时使用共享主机(根据经验),他们会要求您提供帐户的用户名和密码,一旦您输入,您的 web.config 就会更改。因此,请尝试一下,如果它不起作用并且您无权设置权限,那么恐怕您必须研究其他方法。
祝你好运!
http://msdn.microsoft.com/en-us/library/system.configuration.configuration.connectionstrings.aspx
Edit:
http://msdn.microsoft.com/en-us/library/system.configuration.connectionstringssection.aspx
Also, as pointed out by the others, you need to set the correct permissions but sometimes using shared hosting (from experience) they ask you for the username and password of your account and once you enter that, your web.config is changed. So try it and if it doesn't work and you don't have access to set the permissions then I'm afraid you have to look into something else.
Good luck!
使用
WebConfigurationManager
类,如下所示由于它是非常敏感的信息,因此需要按照此网站(建议的链接)上的说明设置适当的权限作者:大卫·斯特拉顿)。
Use the
WebConfigurationManager
class as shown here.As it is very sensitive information, proper permissions need to be set as explained on this site (link proposed by David Stratton).