How Do I get ConfigurationSettings from the calling assembly?

Discussion in 'ASP .Net' started by Rob Mayo, Sep 22, 2003.

  1. Rob Mayo

    Rob Mayo Guest

    I'm developing a server control for our intranet. This control is only going
    to be used in two applications on the server, but they must be separate.

    It has been established that these 2 apps will use a specifically named key
    from their respective web.config's. I want the control to use that key
    regardless of which application it's being used on.

    How can I get that key from the application?

    I considered creating a config file for the control, but that would be more
    to maintain. We're using config files, because we don't want to use the
    registry anymore. So the registry's out.

    for example

    visual basic
    code:-----------------------------------------------------------------------
    -------'In the app
    Dim strConn As String = ConfigurationSettings.AppSettings.Item("EQDB")

    'I want (in the control)
    Dim strConn As String =
    CallingApp.ConfigurationSettings.AppSettings.Item("EQDB")-------------------
    -----------------------------------------------------------

    I could pass in the values I want directly from the app(s), but that would
    mean I would have to do that for every page in the app(s) that wanted to use
    the control. That would be a maintenance nightmare.

    I'm developing for developers, so I want them to be able to use this control
    with as little hassle as possible.

    Any ideas as to how to get this?
    Rob Mayo, Sep 22, 2003
    #1
    1. Advertising

  2. Create one config file for each app (web.config) and make sure they both
    contain something like:

    <appSettings>
    <add key="EQDB" value="your data here" />

    ...

    </appSettings>

    As you are creating this for other developers, they will certainly be
    comfortable with this approach.



    --
    TJoker, MCSD.NET
    MVP: Paint, Notepad, Solitaire

    ****************************************


    "Rob Mayo" <> wrote in message
    news:...
    > I'm developing a server control for our intranet. This control is only

    going
    > to be used in two applications on the server, but they must be separate.
    >
    > It has been established that these 2 apps will use a specifically named

    key
    > from their respective web.config's. I want the control to use that key
    > regardless of which application it's being used on.
    >
    > How can I get that key from the application?
    >
    > I considered creating a config file for the control, but that would be

    more
    > to maintain. We're using config files, because we don't want to use the
    > registry anymore. So the registry's out.
    >
    > for example
    >
    > visual basic
    >

    code:-----------------------------------------------------------------------
    > -------'In the app
    > Dim strConn As String = ConfigurationSettings.AppSettings.Item("EQDB")
    >
    > 'I want (in the control)
    > Dim strConn As String =
    >

    CallingApp.ConfigurationSettings.AppSettings.Item("EQDB")-------------------
    > -----------------------------------------------------------
    >
    > I could pass in the values I want directly from the app(s), but that would
    > mean I would have to do that for every page in the app(s) that wanted to

    use
    > the control. That would be a maintenance nightmare.
    >
    > I'm developing for developers, so I want them to be able to use this

    control
    > with as little hassle as possible.
    >
    > Any ideas as to how to get this?
    >
    >
    TJoker .NET [MVP], Sep 22, 2003
    #2
    1. Advertising

  3. Rob Mayo

    Pete Davis Guest

    Well, using: this.Page.Request.ApplicationPath from the WebControl, you
    should be able to access the web.config file, though I'm unsure of what
    permission issues might be involved, as I haven't done this myself. At that
    point you could parse the XML using an XML reader.

    Just an idea.

    Pete


    "Rob Mayo" <> wrote in message
    news:...
    > I'm developing a server control for our intranet. This control is only

    going
    > to be used in two applications on the server, but they must be separate.
    >
    > It has been established that these 2 apps will use a specifically named

    key
    > from their respective web.config's. I want the control to use that key
    > regardless of which application it's being used on.
    >
    > How can I get that key from the application?
    >
    > I considered creating a config file for the control, but that would be

    more
    > to maintain. We're using config files, because we don't want to use the
    > registry anymore. So the registry's out.
    >
    > for example
    >
    > visual basic
    >

    code:-----------------------------------------------------------------------
    > -------'In the app
    > Dim strConn As String = ConfigurationSettings.AppSettings.Item("EQDB")
    >
    > 'I want (in the control)
    > Dim strConn As String =
    >

    CallingApp.ConfigurationSettings.AppSettings.Item("EQDB")-------------------
    > -----------------------------------------------------------
    >
    > I could pass in the values I want directly from the app(s), but that would
    > mean I would have to do that for every page in the app(s) that wanted to

    use
    > the control. That would be a maintenance nightmare.
    >
    > I'm developing for developers, so I want them to be able to use this

    control
    > with as little hassle as possible.
    >
    > Any ideas as to how to get this?
    >
    >
    Pete Davis, Sep 22, 2003
    #3
  4. Rob Mayo

    alien2_51 Guest

    You could put all your configuration setting in your machine.config then all
    your apps would have the appsetting section inherited from machin.config

    "Rob Mayo" <> wrote in message
    news:...
    > I'm developing a server control for our intranet. This control is only

    going
    > to be used in two applications on the server, but they must be separate.
    >
    > It has been established that these 2 apps will use a specifically named

    key
    > from their respective web.config's. I want the control to use that key
    > regardless of which application it's being used on.
    >
    > How can I get that key from the application?
    >
    > I considered creating a config file for the control, but that would be

    more
    > to maintain. We're using config files, because we don't want to use the
    > registry anymore. So the registry's out.
    >
    > for example
    >
    > visual basic
    >

    code:-----------------------------------------------------------------------
    > -------'In the app
    > Dim strConn As String = ConfigurationSettings.AppSettings.Item("EQDB")
    >
    > 'I want (in the control)
    > Dim strConn As String =
    >

    CallingApp.ConfigurationSettings.AppSettings.Item("EQDB")-------------------
    > -----------------------------------------------------------
    >
    > I could pass in the values I want directly from the app(s), but that would
    > mean I would have to do that for every page in the app(s) that wanted to

    use
    > the control. That would be a maintenance nightmare.
    >
    > I'm developing for developers, so I want them to be able to use this

    control
    > with as little hassle as possible.
    >
    > Any ideas as to how to get this?
    >
    >
    alien2_51, Sep 22, 2003
    #4
  5. Rob Mayo

    Leon Jollans Guest

    System.Configuration.ConfigurationSettings.AppSettings[key] will work as per
    the scope of the application you are using the control in.

    "Rob Mayo" <> wrote in message
    news:...
    > I'm developing a server control for our intranet. This control is only

    going
    > to be used in two applications on the server, but they must be separate.
    >
    > It has been established that these 2 apps will use a specifically named

    key
    > from their respective web.config's. I want the control to use that key
    > regardless of which application it's being used on.
    >
    > How can I get that key from the application?
    >
    > I considered creating a config file for the control, but that would be

    more
    > to maintain. We're using config files, because we don't want to use the
    > registry anymore. So the registry's out.
    >
    > for example
    >
    > visual basic
    >

    code:-----------------------------------------------------------------------
    > -------'In the app
    > Dim strConn As String = ConfigurationSettings.AppSettings.Item("EQDB")
    >
    > 'I want (in the control)
    > Dim strConn As String =
    >

    CallingApp.ConfigurationSettings.AppSettings.Item("EQDB")-------------------
    > -----------------------------------------------------------
    >
    > I could pass in the values I want directly from the app(s), but that would
    > mean I would have to do that for every page in the app(s) that wanted to

    use
    > the control. That would be a maintenance nightmare.
    >
    > I'm developing for developers, so I want them to be able to use this

    control
    > with as little hassle as possible.
    >
    > Any ideas as to how to get this?
    >
    >
    Leon Jollans, Sep 22, 2003
    #5
  6. Rob Mayo

    Rob Mayo Guest

    They already do.

    I wanted to know how to access that from the server control. There seemed to
    be no visibly accessible property for accessing ConfigurationSettings of the
    apps from the server control.

    What I ended up doing was setting a global variable in the apps' Global.aspx
    which was set to the value in the web.configs. From there I was able to
    access that from the server control's Parent.Application object

    "TJoker .NET [MVP]" <> wrote in message
    news:#...
    > Create one config file for each app (web.config) and make sure they both
    > contain something like:
    >
    > <appSettings>
    > <add key="EQDB" value="your data here" />
    >
    > ...
    >
    > </appSettings>
    >
    > As you are creating this for other developers, they will certainly be
    > comfortable with this approach.
    >
    >
    >
    > --
    > TJoker, MCSD.NET
    > MVP: Paint, Notepad, Solitaire
    >
    > ****************************************
    >
    >
    > "Rob Mayo" <> wrote in

    message
    > news:...
    > > I'm developing a server control for our intranet. This control is only

    > going
    > > to be used in two applications on the server, but they must be separate.
    > >
    > > It has been established that these 2 apps will use a specifically named

    > key
    > > from their respective web.config's. I want the control to use that key
    > > regardless of which application it's being used on.
    > >
    > > How can I get that key from the application?
    > >
    > > I considered creating a config file for the control, but that would be

    > more
    > > to maintain. We're using config files, because we don't want to use the
    > > registry anymore. So the registry's out.
    > >
    > > for example
    > >
    > > visual basic
    > >

    >

    code:-----------------------------------------------------------------------
    > > -------'In the app
    > > Dim strConn As String = ConfigurationSettings.AppSettings.Item("EQDB")
    > >
    > > 'I want (in the control)
    > > Dim strConn As String =
    > >

    >

    CallingApp.ConfigurationSettings.AppSettings.Item("EQDB")-------------------
    > > -----------------------------------------------------------
    > >
    > > I could pass in the values I want directly from the app(s), but that

    would
    > > mean I would have to do that for every page in the app(s) that wanted to

    > use
    > > the control. That would be a maintenance nightmare.
    > >
    > > I'm developing for developers, so I want them to be able to use this

    > control
    > > with as little hassle as possible.
    > >
    > > Any ideas as to how to get this?
    > >
    > >

    >
    >
    Rob Mayo, Sep 22, 2003
    #6
  7. You can use the same code you showed:
    System.Configuration.ConfigurationSettings.AppSettings.Item("EQDB")
    I have code using this approach and it works. Any code will have access to
    whatever is in the application config file of the application that loaded
    the code (your server control, for example).
    It seems like a simple matter of missing Imports (C# using) statements..



    --
    TJoker, MCSD.NET
    MVP: Paint, Notepad, Solitaire

    ****************************************


    "Rob Mayo" <> wrote in message
    news:...
    > They already do.
    >
    > I wanted to know how to access that from the server control. There seemed

    to
    > be no visibly accessible property for accessing ConfigurationSettings of

    the
    > apps from the server control.
    >
    > What I ended up doing was setting a global variable in the apps'

    Global.aspx
    > which was set to the value in the web.configs. From there I was able to
    > access that from the server control's Parent.Application object
    >
    > "TJoker .NET [MVP]" <> wrote in message
    > news:#...
    > > Create one config file for each app (web.config) and make sure they both
    > > contain something like:
    > >
    > > <appSettings>
    > > <add key="EQDB" value="your data here" />
    > >
    > > ...
    > >
    > > </appSettings>
    > >
    > > As you are creating this for other developers, they will certainly be
    > > comfortable with this approach.
    > >
    > >
    > >
    > > --
    > > TJoker, MCSD.NET
    > > MVP: Paint, Notepad, Solitaire
    > >
    > > ****************************************
    > >
    > >
    > > "Rob Mayo" <> wrote in

    > message
    > > news:...
    > > > I'm developing a server control for our intranet. This control is only

    > > going
    > > > to be used in two applications on the server, but they must be

    separate.
    > > >
    > > > It has been established that these 2 apps will use a specifically

    named
    > > key
    > > > from their respective web.config's. I want the control to use that key
    > > > regardless of which application it's being used on.
    > > >
    > > > How can I get that key from the application?
    > > >
    > > > I considered creating a config file for the control, but that would be

    > > more
    > > > to maintain. We're using config files, because we don't want to use

    the
    > > > registry anymore. So the registry's out.
    > > >
    > > > for example
    > > >
    > > > visual basic
    > > >

    > >

    >

    code:-----------------------------------------------------------------------
    > > > -------'In the app
    > > > Dim strConn As String = ConfigurationSettings.AppSettings.Item("EQDB")
    > > >
    > > > 'I want (in the control)
    > > > Dim strConn As String =
    > > >

    > >

    >

    CallingApp.ConfigurationSettings.AppSettings.Item("EQDB")-------------------
    > > > -----------------------------------------------------------
    > > >
    > > > I could pass in the values I want directly from the app(s), but that

    > would
    > > > mean I would have to do that for every page in the app(s) that wanted

    to
    > > use
    > > > the control. That would be a maintenance nightmare.
    > > >
    > > > I'm developing for developers, so I want them to be able to use this

    > > control
    > > > with as little hassle as possible.
    > > >
    > > > Any ideas as to how to get this?
    > > >
    > > >

    > >
    > >

    >
    >
    TJoker .NET [MVP], Sep 22, 2003
    #7
    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. Bassel Tabbara [MSFT]

    RE: ConfigurationSettings.AppSettings Error

    Bassel Tabbara [MSFT], Jul 2, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    694
    Bassel Tabbara [MSFT]
    Jul 7, 2003
  2. Guest
    Replies:
    3
    Views:
    3,713
    =?Utf-8?B?TG9yaSBNY0RvbmFsZA==?=
    Feb 23, 2004
  3. Replies:
    3
    Views:
    1,807
  4. Rob Mayo

    How Do I get ConfigurationSettings from the calling assembly?

    Rob Mayo, Sep 22, 2003, in forum: ASP .Net Building Controls
    Replies:
    6
    Views:
    105
    TJoker .NET [MVP]
    Sep 22, 2003
  5. Rob Mayo
    Replies:
    6
    Views:
    153
    TJoker .NET [MVP]
    Sep 22, 2003
Loading...

Share This Page