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 8594467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:12:22+00:00 2026-06-12T00:12:22+00:00

Several places in my code a serviceurl is retrievet from app.config like this ConfigurationManager.AppSettings[ServerURL];

  • 0

Several places in my code a serviceurl is retrievet from app.config like this ConfigurationManager.AppSettings["ServerURL"];

Now I would like to make it possible to the users to specify the service url as a commandline argument. If no argument is specified the serviceurl from app.config must be used.

In Main I can do the following:

if(args[0] != null)
ConfigurationManager.AppSettings["ServerURL"] = args[0]

It seems to work, but can i rely on that AppSettings[“ServerURL”] isnt reloaded from app.config? I know about ConfigurationManager.RefreshSection but it isnt used.

  • 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-12T00:12:24+00:00Added an answer on June 12, 2026 at 12:12 am

    Instead of changing the AppSettings values from code, you should have another class that wraps ConfigurationManager and provides the logic for the value replacement:

    public static class Conf {
        public static string ServerURLOverride { get; set; }
    
        public static string ServerUrl {
            get { return ServerURLOverride ?? ConfigurationManager.AppSettings["ServerURL"]; }
        }
    }
    

    And in Main():

    if (args.Length > 0 && args[0] != null)
        Conf.ServerURLOverride = args[0];
    

    This will also simplify unit testing.

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

Sidebar

Related Questions

If I have an integer like this in several places in my code... int
in several places in my current code I do this (or something like it
on several places in same controller i have code like: $publications = $this->paginate('Publication', $conditions);
I have seen this show up several places in code, never with an explanation,
I have used constant co-ordinates in code in several places in my iPhone app,
I have a ListView template that's being used in several places and I'd like
I love Asserts and code readability but not code duplication, and in several places
I have code something like this in an IRepository implementation in Linq to Sql:
I've found the piece of code below in several places around the web and
I'm using the new Resharper version 6. In several places in my code it

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.