Share AppSettings configuration between a service Web and an asp.net web application

Discussion in 'ASP .Net' started by Oriane, Mar 30, 2009.

  1. Oriane

    Oriane Guest

    Hi there,
    In a web service (A), I would like to read and modify a web site (B)
    configuration file. My goal is only to modify the appSettings section.

    In order to avoid mistakes, I would like not to have these settings in the
    default web.config file but, say, in a "settings.config" file, located in
    the webservice virtual directory.

    On IIS6, my webservice A is a web application from the B web site. So, the A
    source files are in a (virtual) subdirectory of the B source files
    directory.

    Does it seem possible ?
    ___________________________________________________________________________________________________
    Now, for a start, I've tried to read the settings in the web.config file of
    A:

    <?xml version="1.0"?>
    <Configuration>
    <...>
    <appSettings>
    <add key="a" value="aaa"/>
    </appSettings>
    <connectionStrings>
    <clear/>
    <add name="Stibil" connectionString="Server=.\sql2008..."/>
    </connectionStrings>

    I use this code:

    System.Configuration.Configuration rootWebConfig1 =
    WebConfigurationManager.OpenWebConfiguration(null);
    if (rootWebConfig1.AppSettings.Settings.Count > 0)
    {
    KeyValueConfigurationElement customSetting =
    rootWebConfig1.AppSettings.Settings[param];
    if (customSetting != null)
    return customSetting.Value;
    }
    return "Nothing";

    And the fact is that "rootWebConfig1.AppSettings.Settings.Count" returns
    0...
    However,
    "rootWebConfig1.AppSettings.ConnectionStrings..ConnectionStrings.ConnectionStrings.Count"
    is 1.

    I can't see where is my mistake...

    __________________________________________________________________________________________________
    Now if I want to read a config file (in my web service or in my web site),
    which is not the default "web.config" file, possibly located in a virtual
    subdirectory, what parameter do I need in the "OpenWebConfiguration" method
    ?

    Best regards
    Oriane, Mar 30, 2009
    #1
    1. Advertising

  2. Oriane

    Steven Cheng Guest

    Hi Oriane,

    From your description, you want to use code to open the Web.config file of
    the IIS root site and modify the AppSettings section in it, correct?

    Based on my research, the WebConfigurationManager class can only open
    "web.config" file, so if you use your own custom config file, it will not
    work with it. And to open the web.config file for the IIS root site, you
    only need to supply the root site virutal path which is simply "/"

    Here is a test function which open & modify web.config file in IIS site
    root(from an ASP.NET application/virtual directory under the site root):

    ==================

    public partial class ConfigTestPage : System.Web.UI.Page
    {
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnAddEntry_Click(object sender, EventArgs e)
    {
    Configuration config =
    WebConfigurationManager.OpenWebConfiguration("/");
    config.AppSettings.Settings.Add("Item_" + DateTime.Now.Ticks,
    "Value_" + DateTime.Now.Ticks);
    Response.Write("<br/>Physical path: " + config.FilePath);
    config.Save(ConfigurationSaveMode.Modified);
    }
    }
    =================

    Sincerely,

    Steven Cheng

    Microsoft MSDN Online Support Lead


    Delighting our customers is our #1 priority. We welcome your comments and
    suggestions about how we can improve the support we provide to you. Please
    feel free to let my manager know what you think of the level of service
    provided. You can send feedback directly to my manager at:
    .

    ==================================================
    Get notification to my posts through email? Please refer to
    http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

    Note: MSDN Managed Newsgroup support offering is for non-urgent issues
    where an initial response from the community or a Microsoft Support
    Engineer within 2 business day is acceptable. Please note that each follow
    up response may take approximately 2 business days as the support
    professional working with you may need further investigation to reach the
    most efficient resolution. The offering is not appropriate for situations
    that require urgent, real-time or phone-based interactions. Issues of this
    nature are best handled working with a dedicated Microsoft Support Engineer
    by contacting Microsoft Customer Support Services (CSS) at
    http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
    ==================================================
    This posting is provided "AS IS" with no warranties, and confers no rights.

    --------------------
    >From: "Oriane" <>
    >Subject: Share AppSettings configuration between a service Web and an

    asp.net web application
    >Date: Mon, 30 Mar 2009 10:30:28 +0200


    >
    >Hi there,
    >In a web service (A), I would like to read and modify a web site (B)
    >configuration file. My goal is only to modify the appSettings section.
    >
    >In order to avoid mistakes, I would like not to have these settings in the
    >default web.config file but, say, in a "settings.config" file, located in
    >the webservice virtual directory.
    >
    >On IIS6, my webservice A is a web application from the B web site. So, the

    A
    >source files are in a (virtual) subdirectory of the B source files
    >directory.
    >
    >Does it seem possible ?
    >___________________________________________________________________________

    ________________________
    >Now, for a start, I've tried to read the settings in the web.config file of
    >A:
    >
    ><?xml version="1.0"?>
    ><Configuration>
    > <...>
    > <appSettings>
    > <add key="a" value="aaa"/>
    > </appSettings>
    > <connectionStrings>
    > <clear/>
    > <add name="Stibil" connectionString="Server=.\sql2008..."/>
    > </connectionStrings>
    >
    Steven Cheng, Mar 30, 2009
    #2
    1. Advertising

  3. Oriane

    Oriane Guest

    Hi Steven,

    ""Steven Cheng"" <> a écrit dans le message de
    news:...
    > Hi Oriane,
    >
    > From your description, you want to use code to open the Web.config file of
    > the IIS root site and modify the AppSettings section in it, correct?

    Yes. Correct !


    > Based on my research, the WebConfigurationManager class can only open
    > "web.config" file, so if you use your own custom config file, it will not
    > work with it. And to open the web.config file for the IIS root site, you
    > only need to supply the root site virutal path which is simply "/"
    >
    > Here is a test function which open & modify web.config file in IIS site
    > root(from an ASP.NET application/virtual directory under the site root):

    Ok thanks a lot.

    Oriane
    Oriane, Mar 30, 2009
    #3
  4. Oriane

    Steven Cheng Guest

    Thanks for your reply Oriane,

    If you have any further question on this, please feel free to post here.

    Sincerely,

    Steven Cheng

    Microsoft MSDN Online Support Lead


    Delighting our customers is our #1 priority. We welcome your comments and
    suggestions about how we can improve the support we provide to you. Please
    feel free to let my manager know what you think of the level of service
    provided. You can send feedback directly to my manager at:
    .


    --------------------
    >From: "Oriane" <>
    >Subject: Re: Share AppSettings configuration between a service Web and an

    asp.net web application
    >Date: Mon, 30 Mar 2009 18:15:50 +0200


    >
    >Hi Steven,
    >
    >""Steven Cheng"" <> a écrit dans le message de
    >news:...
    >> Hi Oriane,
    >>
    >> From your description, you want to use code to open the Web.config file

    of
    >> the IIS root site and modify the AppSettings section in it, correct?

    >Yes. Correct !
    >
    >
    >> Based on my research, the WebConfigurationManager class can only open
    >> "web.config" file, so if you use your own custom config file, it will not
    >> work with it. And to open the web.config file for the IIS root site, you
    >> only need to supply the root site virutal path which is simply "/"
    >>
    >> Here is a test function which open & modify web.config file in IIS site
    >> root(from an ASP.NET application/virtual directory under the site root):

    >Ok thanks a lot.
    >
    >Oriane
    >
    >
    Steven Cheng, Mar 31, 2009
    #4
    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. Luis Esteban Valencia

    Share Data between ASP and ASP.net?

    Luis Esteban Valencia, Nov 3, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    1,525
    Saravana
    Nov 3, 2004
  2. Sergei Shelukhin
    Replies:
    1
    Views:
    1,142
    David
    Mar 29, 2007
  3. Randy Smith
    Replies:
    2
    Views:
    373
    Mark S. Milley, MCSD (BinarySwitch)
    Jul 3, 2007
  4. Eddie Leung

    difference between .Net web application and .Net web service

    Eddie Leung, Oct 22, 2004, in forum: ASP .Net Web Services
    Replies:
    1
    Views:
    112
    Dan Rogers
    Nov 15, 2004
  5. Saraswati lakki
    Replies:
    0
    Views:
    1,322
    Saraswati lakki
    Jan 6, 2012
Loading...

Share This Page