how to tell if code running in asp.net context?

G

Guest

I need to do some caching. If my code is running a part of asp.net then I
would use caching, otherwise I'll just store my data in an object.

And my question is now do I determine at run time if the code is running as
part of asp.net?

I know if HttpContext is not available I get an exception, but there must be
a graceful way to determine it.

Thank you.
 
M

Marina

See if there is an httpcontext. If there is, use that. Otherwise store data
in the object.
 
G

Guest

Hi Marina - my q was how do I determine that? HttpContext is a class, and
HttpContext.Current is an undefined object. I could catch exception but maybe
there is a cleaner way to do this? Thanks
 
B

bruce barker

try an if statement:

if (HttpContext.Current != null)
{
// we are running under asp.net
}
else
{
// we are not running under asp.net
}


-- bruce (sqlwork.com)
 

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