473,326 Members | 2,175 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

How Do I get ConfigurationSettings from the calling assembly?

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?
Nov 17 '05 #1
6 1308
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" <Ro***************@WestNO-0-SPAMonSolutions.com> wrote in message
news:OM**************@TK2MSFTNGP09.phx.gbl...
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?

Nov 17 '05 #2
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" <Ro***************@WestNO-0-SPAMonSolutions.com> wrote in message
news:OM**************@TK2MSFTNGP09.phx.gbl...
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?

Nov 17 '05 #3
System.Configuration.ConfigurationSettings.AppSett ings[key] will work as per
the scope of the application you are using the control in.

"Rob Mayo" <Ro***************@WestNO-0-SPAMonSolutions.com> wrote in message
news:OM**************@TK2MSFTNGP09.phx.gbl...
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?

Nov 17 '05 #4
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" <Ro***************@WestNO-0-SPAMonSolutions.com> wrote in message
news:OM**************@TK2MSFTNGP09.phx.gbl...
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?

Nov 17 '05 #5
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]" <no****@nonono.no> wrote in message
news:#l*************@TK2MSFTNGP11.phx.gbl...
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" <Ro***************@WestNO-0-SPAMonSolutions.com> wrote in message news:OM**************@TK2MSFTNGP09.phx.gbl...
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?


Nov 17 '05 #6
You can use the same code you showed:
System.Configuration.ConfigurationSettings.AppSett ings.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" <Ro***************@WestNO-0-SPAMonSolutions.com> wrote in message
news:e6**************@tk2msftngp13.phx.gbl...
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]" <no****@nonono.no> wrote in message
news:#l*************@TK2MSFTNGP11.phx.gbl...
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" <Ro***************@WestNO-0-SPAMonSolutions.com> wrote in

message
news:OM**************@TK2MSFTNGP09.phx.gbl...
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?



Nov 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: serge calderara | last post by:
Dear all, I have define a configuration file for my application with different section groups and settings belonging to each individual group like as follow : ...
6
by: Rob Mayo | last post by:
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...
0
by: awf_ng | last post by:
I'm writing a MMC snapin in .NET. The problem I have is that I need to access configuration information, which needs to be stored in the App.config file. Being a MMC snapin, if I use the...
3
by: Random | last post by:
I'm writing a class library for my web app data access, but don't want to hard code the database connection string in the class. Nor do I want to pass the connection string in from the web app...
2
by: Bruce W.1 | last post by:
I started a new web app.. In my Page_Load method I do this: string strConnTxt = ConfigurationSettings.AppSettings; and the compiler gives this error: The type or namespace name...
8
by: Mark | last post by:
Could someone provide me with details or a link on how the line of code executes underneath the hood? Assume it's executed in an ASP.NET application. string blah =...
3
by: John | last post by:
Hi If I use ConfigurationSettings.AppSettings.Set("KeyName", "KeyValue"), where does the KeyName/KeyValue combination ends up? In a file? In windows registry? Thanks Regards
7
by: =?Utf-8?B?UVNJRGV2ZWxvcGVy?= | last post by:
I have a C# logging assembly with a static constructor and methods that is called from another C# Assembly that is used as a COM interface for a VB6 Application. Ideally I need to build a file...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.