application settings

Discussion in 'ASP .Net' started by Andy B, Dec 9, 2008.

  1. Andy B

    Andy B Guest

    How hard is it to access/modify application settings in the web.config from
    web pages?
     
    Andy B, Dec 9, 2008
    #1
    1. Advertising

  2. re:
    !> How hard is it to access/modify application settings in the web.config from web pages?

    Quite easy...with the caveat that you'll lose all application data as a result,
    because the application will restart as soon as you modify web.config.

    Look into the WebConfigurationManager.OpenWebConfiguration Method :

    http://msdn.microsoft.com/en-us/lib...onfigurationmanager.openwebconfiguration.aspx

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




    Juan T. Llibre, asp.net MVP
    asp.net faq : http://asp.net.do/faq/
    foros de asp.net, en espaƱol : http://asp.net.do/foros/
    ======================================
    "Andy B" <> wrote in message news:...
    > How hard is it to access/modify application settings in the web.config from web pages?
    >
    >
    >
     
    Juan T. Llibre, Dec 9, 2008
    #2
    1. Advertising

  3. Andy B

    Andy B Guest

    "Which means that, apart from very exceptional circumstances, modifying
    web.config at runtime is almost always the wrong solution - what are you
    trying to achieve here...?"

    I need to have a set of application settings that can be changed and used in
    the website. Kind of like system settings profile instead of a user profile.
    For an example, a setting I want to have is "Number of News articles to show
    on home page?" I just don't know where the best place to keep these would
    be. a DB doesn't seem to be too practicle for something like this. Possibly
    some sort of settings file of some kind?
     
    Andy B, Dec 9, 2008
    #3
  4. Andy B

    George Guest

    Sorry, I just jump in.

    I use external XML file which is desterilized into my 'Config' object with
    XmlSerializer when application loading (event in Global.asax). And in code I
    am using that Config object

    (in Psedoucode)
    class clsGlobal
    {
    static public clsConfig _objConfig;
    public static void Init()
    {
    _objConfig = XmlSerializer.Deserialize('~/my.xml');
    }
    }

    Use in code.
    int iLinesPerPage = clsGlobal._objConfig._iLinesPerPage;

    -----------------------------------------------
    To avoid watching my.xml for changes I create some dummy.aspx page (only me
    or admin knows about). Which does only

    clsGlobal.Init();
    Response.Write("OK");

    Then whenever i change my.xml i hit dummy.aspx to refresh new settings.
    So basically the same thing as if in web.config except i avoid restarting
    application.

    But of course as Mark said you need to determine where to store your config
    values based on the use. If user needs to be able to change that kind of
    settings then my way might be not good idea.


    George.





    "Mark Rae [MVP]" <> wrote in message
    news:%...
    > "Andy B" <> wrote in message
    > news:...
    >
    >>> "Which means that, apart from very exceptional circumstances, modifying
    >>> web.config at runtime is almost always the wrong solution - what are you
    >>> trying to achieve here...?"

    >>
    >> I need to have a set of application settings that can be changed and used
    >> in the website. Kind of like system settings profile instead of a user
    >> profile. For an example, a setting I want to have is "Number of News
    >> articles to show on home page?" I just don't know where the best place to
    >> keep these would be. A DB doesn't seem to be too practical for something
    >> like this. Possibly some sort of settings file of some kind?

    >
    > Do you need to change this value on a regular basis?
    >
    > Do you need to change this value while the site is in use?
    >
    >
    > --
    > Mark Rae
    > ASP.NET MVP
    > http://www.markrae.net
     
    George, Dec 9, 2008
    #4
  5. Andy B

    Andy B Guest

    "Do you need to change this value on a regular basis?"

    I don't think this particular value will need to be changed on a regular
    basis. Because of the nature of the settings, I would expect that they will
    be used with some regularity (at least I need to program for the
    possibility).

    "Do you need to change this value while the site is in use?"

    All of the settings I am thinking about need to be set while the application
    is in use and running.
     
    Andy B, Dec 9, 2008
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Damian
    Replies:
    3
    Views:
    12,513
    Jim Cheshire [MSFT]
    Dec 30, 2003
  2. Venkat Chellam
    Replies:
    0
    Views:
    331
    Venkat Chellam
    Oct 28, 2004
  3. Siegfried Heintze
    Replies:
    0
    Views:
    2,284
    Siegfried Heintze
    Oct 24, 2005
  4. leeanne
    Replies:
    0
    Views:
    1,881
    leeanne
    Sep 24, 2008
  5. donet programmer
    Replies:
    3
    Views:
    1,559
    Gregory A. Beamer
    Nov 20, 2009
Loading...

Share This Page