简体   繁体   English

以编程方式更新web.config是不好的做法吗?

[英]Is it bad practice to programmatically update the web.config?

I've built an installer that creates a website, application pool, and then assigns the website to the app pool. 我已经构建了一个安装程序,用于创建网站,应用程序池,然后将网站分配给应用程序池。 As part of this I allow the user to input different settings for various connection strings (allows the developer to set them to DEV / UAT etc.). 在此过程中,我允许用户为各种连接字符串输入不同的设置(允许开发人员将其设置为DEV / UAT等)。 I then modify the web.config with the settings input by the user. 然后,我使用用户输入的设置来修改web.config。

As this is something that will only be installed by a small bunch of developers I'm not concerned with the security of the input (I'm aware they could put in anything), but more with whether it's considered bad practice to modify the web.config in this way? 因为这只会由一小部分开发人员安装,所以我不关心输入的安全性(我知道他们可以放入任何东西),但是更关心的是修改网络是否被认为是不好的做法.config以这种方式?

I've read a few questions on here regarding how people do this and generally in each one there is someone saying that it's not a good idea to do this. 我在这里阅读了有关人们如何执行此操作的几个问题,通常每个人中有人说这样做不是一个好主意。 The second answer on this question states that doing so will restart your application. 关于此问题的第二个答案指出,这样做将重新启动您的应用程序。 I can see how this could cause problems if your user is in the middle of using the app, but for my scenario this isn't relevant. 我可以看到,如果您的用户正在使用该应用程序,这可能会导致问题,但是对于我的情况,这无关紧要。 Is this the only reason to consider when doing this? 这是这样做时唯一要考虑的理由吗?

web.config is like the .htaccess file, in wordpress some plugins automatically updates these files accordingly. web.config就像.htaccess文件一样,在wordpress中,某些插件会相应地自动更新这些文件。
This links might help you, I did have this same question the other day 此链接可能会对您有所帮助,前几天我确实有同样的问题

Change a web.config programmatically with C# (.NET) 使用C#(.NET)以编程方式更改web.config

The warnings are usually applied when someone is talking about having an asp.net website update its own web.config file. 通常,当有人在谈论让asp.net网站更新其自己的 web.config文件时,将应用警告。 But as I understand it, you're talking about updating it from your installer, and this happens before the site is used, so it should be fine. 但是据我了解,您是在谈论从安装程序进行更新,这种情况发生在使用网站之前,因此应该没问题。


And, of course, think about it the other way - what's your alternative to manipulating these files programmatically? 而且,当然,可以用另一种方式来考虑-用编程方式处理这些文件的替代方法是什么? Do you have any means at your disposal for manipulating these files that doesn't, at some point, have some program open the file and write to it? 您是否有任何手段来处理这些文件,而在某些时候,没有某种程序可以打开文件并写入文件?

Notepad? 记事本? It's a program. 这是一个程序。

IIS Manager? IIS管理器? It's a program. 这是一个程序。

Your installer? 您的安装程序? It's a program. 这是一个程序。

Just a (perhaps obvious) thought: Be careful not to overwrite any manual changes added after the installation. 只是一个(也许很明显)的想法:注意不要覆盖安装后添加的任何手动更改。

If I had made some custom changes to a config file, I would not want them to be overwritten by a program. 如果我对配置文件进行了一些自定义更改,则我不希望它们被程序覆盖。 It does not sound as if this would happen in your scenario though, so if the solution works for you, I can't see any real problem. 但这听起来好像不会发生在您的情况中,所以如果该解决方案适合您,我看不到任何实际问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM