How to determine in BL if a Web app is running

Posts   
 
    
alex
User
Posts: 68
Joined: 30-Mar-2004
# Posted on: 27-Jan-2005 15:46:48   

Hi,

I have code in my Business Layer that checks some Session variables. This code should be executed only if a Web app is running. When I access the same method from NUnit, for example, I don't want this code to be executed because session variables are not available.

Does anyone know how to determine in C# code whether or not a Web app is running, or whether or not Session object exists?


if (HttpContext.Current.Session["schema"] != null)
{
   // Do something
}

When I run from NUnit, I get the NullReferenceException in the first line.

Thanks in advance for your help.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39801
Joined: 17-Aug-2003
# Posted on: 27-Jan-2005 18:23:36   

You get teh error because HttpContext.Current is null. (wild guess, but that's what I'd expect)

Frans Bouma | Lead developer LLBLGen Pro
alex
User
Posts: 68
Joined: 30-Mar-2004
# Posted on: 27-Jan-2005 18:43:24   

You right.

Thank you very much.