Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
959 views
in Technique[技术] by (71.8m points)

c# - Dynamically change connectionString in web.config

I have the following in my web.config

<connectionStrings>
   <add name="ActiveDirectoryConnection" connectionString="LDAP://ActiveDirectoryDomain1.com" providerName="System.Web.Security.ActiveDirectoryMembershipProvider"/>
</connectionStrings>

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"

In C# code behind how do change the connectionString value?


More info:

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"/>  

Thanks!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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 - Using Settings in C#

When using settings like this, changing the value at runtime is easy:

Properties.Settings.Default.LdapConnectionString = "New Connection String";
Properties.Settings.Default.Save();

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...