See the question and my original answer on StackOverflow

If the code is executing in an ASP.NET context, HttpContext.Current (static) contains the current Http context. You can always test if it's null or not. If it's not null, you will be able to get HttpContext.Current.Request.

However, the identity that resides within this request context ultimately depends on how the web site (IIS, Cassini, IIS express, or custom) handles identity.