Error referencing key value from web.config.

  • Thread starter Thread starter prabu.girirajan
  • Start date Start date
P

prabu.girirajan

Hi,
I have a web application which internally calls certain web methods of
a web service. This web service has a interop to ATL COM Component and
that ATL component calls a .NET assembly.
I would like to access a key value in the .NET assembly. I added this
to the Web.Config of the Web Service however it didnt read the value.
I also tried adding to the Web.config of the Web application however i
am faced with the same problem.

Am I missing any configuration to get this working

Cheers
Prabu
 
Hi Prabu,

How do you configure web.config?

If you put a key under appSettings you can read it using the
ConfigurationManager.

//web.config
<add key="Mykey" value="MyValue" />

//code
string myKey = ConfigurationManager.AppSettings["MyKey"];
 
Hi Morten
Thanks for your quick response.
The web.config setting is

<add key = "MaximumIterations" value="10" />

and in the code
maximumIteration =
Convert.ToInt32(System.Configuration.ConfigurationSettings.AppSettings["MaximumIterations"]);


I have got a method to return all the configuration setting. however
this just does not return anything.
private void GetAllAttributes()
{
for( int i = 0;
i<System.Configuration.ConfigurationSettings.AppSettings.Count; i++)
{
System.Diagnostics.EventLog.WriteEntry("My
Application",System.Configuration.ConfigurationSettings.AppSettings);
}
}

Cheers
Prabu Girirajan

Morten said:
Hi Prabu,

How do you configure web.config?

If you put a key under appSettings you can read it using the
ConfigurationManager.

//web.config
<add key="Mykey" value="MyValue" />

//code
string myKey = ConfigurationManager.AppSettings["MyKey"];



Hi,
I have a web application which internally calls certain web methods of
a web service. This web service has a interop to ATL COM Component and
that ATL component calls a .NET assembly.
I would like to access a key value in the .NET assembly. I added this
to the Web.Config of the Web Service however it didnt read the value.
I also tried adding to the Web.config of the Web application however i
am faced with the same problem.

Am I missing any configuration to get this working

Cheers
Prabu
 
Well, your code should work, although in .Net 2.0 you should use
ConfigurationManager instead of ConfigurationSettings. Both should work..

Could you show me your web.config?

- Morten

Hi Morten
Thanks for your quick response.
The web.config setting is

<add key = "MaximumIterations" value="10" />

and in the code
maximumIteration =
Convert.ToInt32(System.Configuration.ConfigurationSettings.AppSettings["MaximumIterations"]);


I have got a method to return all the configuration setting. however
this just does not return anything.
private void GetAllAttributes()
{
for( int i = 0;
i<System.Configuration.ConfigurationSettings.AppSettings.Count; i++)
{
System.Diagnostics.EventLog.WriteEntry("My
Application",System.Configuration.ConfigurationSettings.AppSettings);
}
}

Cheers
Prabu Girirajan

Morten said:
Hi Prabu,

How do you configure web.config?

If you put a key under appSettings you can read it using the
ConfigurationManager.

//web.config
<add key="Mykey" value="MyValue" />

//code
string myKey = ConfigurationManager.AppSettings["MyKey"];



Hi,
I have a web application which internally calls certain web methodsof
a web service. This web service has a interop to ATL COM Component and
that ATL component calls a .NET assembly.
I would like to access a key value in the .NET assembly. I added this
to the Web.Config of the Web Service however it didnt read the value.
I also tried adding to the Web.config of the Web application however i
am faced with the same problem.

Am I missing any configuration to get this working

Cheers
Prabu
 
Back
Top