简体   繁体   English

如何在web.config之外的ASP.Net中保留连接字符串?

[英]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.

相关问题 ASP.Net的web.config中的连接字符串问题 - connection string issue in web.config of ASP.Net 在ASP.Net Web.config中加密数据库连接字符串 - Encrypt database connection string in ASP.Net Web.config 从asp.net中的Web.config获取连接字符串 - Get Connection String from Web.config in asp.net web.config中的asp.net连接字符串问题 - asp.net connection string problem in web.config 在 ASP.NET MVC 的 web.config 文件中找不到我的连接字符串标记 - Can't find my connection string tag in web.config file in ASP.NET MVC 我如何解决此错误,MVC 4 中 asp.net 的 web.config 中不允许使用“connectionStringName”属性 - How can i resolve this error the 'connectionStringName' attribute is not allowed in web.config of asp.net in MVC 4 如何在asp.net中的web.config位置路径中添加和删除授权用户 - How can I add and remove authorised users from web.config location path in asp.net 如何从 ASP.NET 自定义控件访问 web.config? - How can I access web.config from an ASP.NET Custom Control? 如何在ASP.NET 4.5中访问web.config配置文件属性? - How can I access web.config Profile properties in ASP.NET 4.5? 如何在TFS2017 for ASP.NET应用程序上进行web.config转换 - How can I make a web.config tranformation on the TFS2017 for ASP.NET application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM