在c#中切换连接字符串
C# Web 应用程序中是否有针对不同环境切换连接字符串的标准?我目前正在评估哪些方式最安全,包括存储它们的位置。我见过人们只是将它们添加到 Web 配置中,然后使用 if 语句在代码中切换它们,检查它们所在的环境,但这似乎很麻烦。有什么想法吗?谢谢。
Are there any standards for switching out connection strings for different environments in C# web apps? I'm currently evaluating which ways are the most secure including where to store them. I've seen people simply add them to the web config and switch them in code with if statements checking which environment they are on, but this seems cumbersome. Any ideas? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Web 配置转换怎么样?
VS2010 可用
How bout Web config transformation?
It's available with VS2010
我发现此类问题的答案是,如果您必须手动对应用程序的配置执行任何操作,那么您就做错了。请查看有关 Web 部署的 scott hanselmen 博客/视频。这周你度过的最好的 45 分钟。
i find the answer to questions like this is that if you're having to manually do anything to your application's configuration you're doing it wrong. check out this scott hanselmen blog/video on web deploy. the best 45 minutes you'll spend this week.
这应该是您的自动化构建过程的一部分。我是 BuildMaster 的开发人员,它会很容易地处理这个配置文件的困境。基本上,您可以在该工具中为您拥有的每个环境创建一个配置文件“实例”,您甚至可以限制对任何实例的访问,例如,没有开发人员可以看到生产的配置。当您为特定环境配置部署计划时,您可以指定要部署的实例,也可以随时通过该工具手动部署它们。
如果您想了解更多信息,请查看我们的配置文件功能部分。
This should be part of your automated build process. I am a developer for BuildMaster, and it will handle this configuration file dilemma quite easily. Basically, you can create one "instance" of a configuration file in the tool for each environment you have, and you can even restrict access to any instance so for example, no developers could see production's configuration. When you're configuring the deployment plans to a certain environment, you can specify the instance you want to deploy, or you can deploy them manually from the tool at any time.
If you want more information, take a look at our configuration files feature section.