动态改变的connectionString在web.config中 [英] Dynamically change connectionString in web.config
问题描述
我在我的web.config以下
I have the following in my web.config
<connectionStrings>
<add name="ActiveDirectoryConnection" connectionString="LDAP://ActiveDirectoryDomain1.com" providerName="System.Web.Security.ActiveDirectoryMembershipProvider"/>
</connectionStrings>
我需要一个下拉框添加到我的登录页面,允许用户向的connectionString更改为不同的字符串,例如LDAP://ActiveDirectoryDomain2.com
I need to add a dropdown box to my login page that allows the user to change the connectionString to a different string, e.g. "LDAP://ActiveDirectoryDomain2.com"
在背后如何更改连接字符串值?C#code
In C# code behind how do change the connectionString value?
更多信息:
More info:
我遇到的问题是,有4个其他的web.config设置调用一个的connectionString。例如:
The problem I am having is that there are 4 other web.config settings call that one connectionString. For example:
<activeDirectorySecurityContextSettings connectionStringName="ActiveDirectoryConnection" defaultADUserName="ReportUser" defaultADPassword="password"/>
谢谢!
推荐答案
如果一个用户能够更改设置的值,则web.config文件是错误的地方保存设置。
If a user is able to change the value of the Setting, then the web.config file is the wrong place to store the setting.
您应该检查出一个用户级范围的值设置文件来代替。
You should check out a User Scoped value in a Settings file instead.
MSDN - 在C#使用设置
在使用这样的设置,改变在运行时的值很简单:
When using settings like this, changing the value at runtime is easy:
Properties.Settings.Default.LdapConnectionString = "New Connection String";
Properties.Settings.Default.Save();
这篇关于动态改变的connectionString在web.config中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!