Board index » Web Programming » how to tell if code running in asp.net context?

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

Web Programming423
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.


-
 

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

See if there is an httpcontext. If there is, use that. Otherwise store data

in the object.



"Serg" <Serg@discussions.microsoft.com>wrote in message

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





-

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

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





"Marina" wrote:



Quote
See if there is an httpcontext. If there is, use that. Otherwise store data

in the object.



"Serg" <Serg@discussions.microsoft.com>wrote in message

news:762F985E-8C54-4D16-B773-C0A8DBB67619@microsoft.com...

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







-

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

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)





"Serg" <Serg@discussions.microsoft.com>wrote in message

Quote
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





"Marina" wrote:



>See if there is an httpcontext. If there is, use that. Otherwise store

data

>in the object.

>

>"Serg" <Serg@discussions.microsoft.com>wrote in message

>news:762F985E-8C54-4D16-B773-C0A8DBB67619@microsoft.com...

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

>

>

>





-