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

  • Thread starter Thread starter Guest
  • Start date Start date
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.
 
See if there is an httpcontext. If there is, use that. Otherwise store data
in the object.
 
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
 
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

Back
Top