Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9185441
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:16:34+00:00 2026-06-17T19:16:34+00:00

First post, I’m a complete .Net/C# novice thrown in at the deep end! I’ve

  • 0

First post, I’m a complete .Net/C# novice thrown in at the deep end!

I’ve inherited a C# wed application due to someone leaving at work and me being the only one with bandwidth! But not the .Net, C# knowledge!

The app is used by people on different sites all over the world. They log in using the corporate login details and as such they log into different servers depending on where they are located, (Europe, America or India).

The guy who wrote the app couldn’t work out how to switch the ConnectionString in web.config depending on location, so duplicated the whole app for each domain! With the only variation being a single IP address in web.config for each duplicated version of the app! Then did a simple web front page which took the user to “their” version of the app depending on where they said they were in the world!

The first thing I want to do is to move to a single version to maintain, so I need to be able to switch the connection string or how to login?

I’ve spent several days trying to work out how I get to ConnectionString (defined in web.config) from my Login class, only to discover the values set in web.config seem to be read only, so I can’t alter them.

So I guess the first question is, am I barking up the wrong tree? Can I just set all the information that AspNetActiveDirectoryMembershipProvider (see code later) requires and call it from my login class? Or is the ConnectionString route the Ipso facto way to set up connections in .Net/C#? So therefor I do need to find out how to change/specify/add the value at runtime.

Three possibilities I can think of:- (The first is the one I’ve ground to a hult with)

  1. Change the ConnectionString for ADService in my web.config from my Login class?

  2. Change what AspNetActiveDirectoryMembershipProvider uses, so from my Login class magicly get it to use EMEA_ADService or PACIFIC_ADService as defined in web.config?

  3. Is it possible to define a new connectionString and call AspNetActiveDirectoryMembershipProvider all from my Login class, not using web.config for this connection at all?

Here’s a bit of my/his web.config file and my Login class

Cuttings from Web.config

<connectionStrings>
    <add name="ADService" connectionString="LDAP://12.345.67.8" />          *---- Original ConnectionString (IP address changed)----* 
    <add name="EMEA_ADService" connectionString="LDAP://12.345.67.8" />     *---- Added by me playing around unsuccessfully! ----* 
    <add name="PACIFIC_ADService" connectionString="LDAP://12.345.67.9" />  *---- Added by me playing around unsuccessfully! ----* 
    ~
  </connectionStrings>

<authentication mode="Forms">
      <forms loginUrl="~/Login.aspx" timeout="2880" />     *---- The background class for this popup (Login.aspx.cs) is where I'm currently trying to affect ConnectionString----* 
    </authentication>
                                                           *---- Pretty sure this is the bit that actually does the login verification----* 
    <membership defaultProvider="AspNetActiveDirectoryMembershipProvider">
      <providers>
        <clear />
        <add name="AspNetActiveDirectoryMembershipProvider" type="System.Web.Security.ActiveDirectoryMembershipProvider,            System.Web, Version=4.0.0.0, Culture=neutral,            PublicKeyToken=12345678" connectionStringName="ADService" applicationName="/." description="ADService" />
      </providers>
    </membership>

This is as far as I’ve got in my class before finding out that I don’t appear to be able to alter ConnectionString!

Cuttings from Login.aspx.cs

public partial class Login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
         ConnectionStringSettingsCollection connections = ConfigurationManager.ConnectionStrings; //this is now working :)
        string userDomain = Environment.UserDomainName;  //Probably don't need this, it seems to give the login domain on the machine. Don't know yet if that will be the users machine or the server the app runs on?
        if (connections.Count != 0)
        {
            foreach (ConnectionStringSettings connection in connections)
            {
                string testname = connections["ADService"].Name;
                string testConnectionString = connections["ADService"].ConnectionString;
                connections["ADService"].ConnectionString = "LDAP://12.345.67.9";
                testConnectionString = connections["ADService"].ConnectionString;

Any hint would be very welcome!

P.S. I have requested a .Net/C# course at work! 😉

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T19:16:35+00:00Added an answer on June 17, 2026 at 7:16 pm

    You wouldn’t want to alter the existing connection string. Rather, you’d want to alter which connection string your Data Access Layer was using to call different service stacks. You could then choose a connection string at runtime based on whatever input parameters you wanted to use. which in your case might be an IP range.

    asp.net mvc multiple connection strings

    Handling multiple connection strings in ONE DataAccess Layer

    http://msdn.microsoft.com/en-us/library/aa479086.aspx

    The microsoft article is particularly interesting since it actually takes an architectural look at proper patterns for resolving dilemmas like yours. I think you got stuck with the short end of the stick! Best of luck!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

first post here, hoping someone could perhaps shed some light on an issue I've
First post here: -Deep Breath- In order to 'windowise' an app that works pretty
First Post! So I'm working on Windows Mobile application for a class I'm in.
First post, I've been researching this all day and I'm at my wits end!
first post here. I'm a novice programmer as you'll see, and I'm learning to
This is my first post and I'm quite a novice on C++ and compiling
first post here as I'm stuck with my wonderful C++ function. The error I'm
First post here... I normally develop using PHP and Symfony with Propel and ActionScript
first post here, and probably an easy one. I've got the code from Processing's
first post here, I come in peace :) I've searched but can't quite find

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.