[英]How can I persist a connection string in ASP.Net outside of web.config?
I have an ASP.NET MVC application that I distribute as a zip file to customers. 我有一个ASP.NET MVC应用程序,我以zip文件的形式分发给客户。 They then extract it on their servers.
然后,他们将其提取到服务器上。 Everything is stored in a SQL database, but I need to save the connection string and that will get overwritten if it's stored in the web.config and they just copy over all the files.
一切都存储在SQL数据库中,但是我需要保存连接字符串,如果将其存储在web.config中,它们将被覆盖,并且它们只会复制所有文件。 The current implementation creates a simple file in the site directory with the connection string, but in some cases the app pool identity doesn't have permission to write to the filesystem.
当前的实现使用连接字符串在站点目录中创建一个简单文件,但是在某些情况下,应用程序池标识没有写入文件系统的权限。
My first thought was the registry, but it sounds like I'll run into similar permission issues. 我的第一个想法是注册表,但听起来我会遇到类似的权限问题。 Is there a directory that I'm guaranteed to have access to?
是否有我可以访问的目录? Another option would be to have an installer perform this action, but I'd prefer not to have to write an installer.
另一个选择是让安装程序执行此操作,但我不希望不必编写安装程序。
Anything I'm overlooking? 我忽略了什么?
You can use configSource
to load it from a different config file, which you would never overwrite when deploying updates. 您可以使用
configSource
从其他配置文件加载该文件,在部署更新时永远不会覆盖该文件。
This works if you expect customers to manually write that file on initial setup. 如果您希望客户在初始设置时手动写入该文件,则此方法有效。
If you want them to enter the connection string into a UI, the registry (in HKCU only) should be fine; 如果希望他们在用户界面中输入连接字符串,则注册表(仅在HKCU中)应该可以; you should (almost) always have permission to write to the user registry, regardless of filesystem permissions.
无论文件系统权限如何,您都应该(几乎)始终具有写入用户注册表的权限。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.