where am i being called from? (web.config)

  • Thread starter Thread starter suzy
  • Start date Start date
S

suzy

hello,

how do i check from my c# class if it is being called from a asp.net
application or a windows application?

i have some code that reads from the web.config file for webapps, but i want
to default the values to something else if there is no web.config (ie:
windows).

any ideas? thanks.
 
First, a desktop application can also have a config file that looks the same
as a web.config file, so simply the lack of a web.config does not indicate
that it is not a website. (Your application normally does not care where
the config settings came from -- app.config or web.config -- as long as it
has the same structure.)

You might try checking the HttpContext.Current property. If it is null,
then it is probably not a website.
 
suzy said:
hello,

how do i check from my c# class if it is being called from a asp.net
application or a windows application?

i have some code that reads from the web.config file for webapps, but i want
to default the values to something else if there is no web.config (ie:
windows).

any ideas? thanks.

Instead of reading from web.config explicitly, why not use
System.Configuration.ConfigurationSettings.AppSettings? It will return
settings from whichever config file is appropriate.
 
thanks guys. why didn't i think of that!!! :)


Peter Rilling said:
First, a desktop application can also have a config file that looks the same
as a web.config file, so simply the lack of a web.config does not indicate
that it is not a website. (Your application normally does not care where
the config settings came from -- app.config or web.config -- as long as it
has the same structure.)

You might try checking the HttpContext.Current property. If it is null,
then it is probably not a website.
 
Back
Top