Question

We always use SpContext.Current.Web, but then what is difference between httpcontext and spcontext?

Was it helpful?

Solution

SPContext and HttpContext are very distinct objects.

SPContext Represents the context of an HTTP request in Microsoft SharePoint Foundation.

HttpContext Encapsulates all HTTP-specific information about an individual HTTP request.

If you look at their members and properties, you will see that SPContext will allow you to access the SharePoint Object Model (SPSite, SPWeb, SPList, etc.). Also, it is a specific class of the SharePoint ecosystem.

On the other hand, HttpContext is a generic class available not only in SharePoint, but throughout the .Net frameworks that will allow you to grab properties of the web context, such as the user's Session, Cache, User Agent, Browser, and others.

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top