2 out of 11 rated this helpful - Rate this topic

HttpContext.Current Property

Updated: May 2011

Gets or sets the HttpContext object for the current HTTP request.

Namespace:  System.Web
Assembly:  System.Web (in System.Web.dll)
public static HttpContext Current { get; set; }

Property Value

Type: System.Web.HttpContext
The HttpContext for the current HTTP request.

You can also use the Context property to access the HttpContext object for the current HTTP request.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

Date

History

Reason

May 2011

Added a note about Page.Context as an alternative way to get this object.

Customer feedback.

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
Working With HttpContext.Current
http://www.odetocode.com/Articles/112.aspx
Create your own http context
Here's a way to create your httpcontext when you need it
http://novatecno.blogspot.com/2010/02/how-to-create-sharepoint-http-context.html

Cheers,
-Edge
HttpContext.Current can return null
If you use HttpContext.Current outside web request processing it will return null.
Example could be web-parts running inside Visual Studio in design mode or some shared class library which can run in different contexts.
Where to use.

HttpContext.Current is typically used in modules to get access to Request and Response properties and methods

When writing code inside a Page class you can simply use the 'Context' property (which will return HttpContext.Current).