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

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.
 
P

Peter Rilling

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.
 
J

John Saunders

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.
 
S

suzy

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top