且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从ASP.NET应用程序更改web.config

更新时间:2022-05-19 21:50:47

Configuration myConfiguration = WebConfigurationManager.OpenWebConfiguration("~");
//appSettings configuration
myConfiguration.AppSettings.Settings["xxx"].Value = "yyy";
//database connections configuration
myConfiguration.ConnectionStrings.ConnectionStrings["xxxconnection"].ConnectionString = "yyy";
myConfiguration.Save();

http://msdn.microsoft.com/zh-cn/library/system.configuration.configuration.connectionstrings.aspx

编辑:

http://msdn.microsoft.com/zh-cn/library/system.configuration.connectionstringssection.aspx

此外,正如其他人所指出的那样,您需要设置正确的权限,但是有时(使用共享主机)(根据经验),他们会要求您提供帐户的用户名和密码,输入该命令,您的web.config就会更改。因此,请尝试一下,如果它不起作用并且您无权设置权限,那么恐怕您还需要研究其他内容。

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.

祝你好运!