2

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

8

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.