A Context is the entry point into PAPI from which all interrelated publishing objects exist and can be accessed and manipulated.
NOTE: In previous versions of CMS, what we refer to as Context was called Autosession. Autosession is still available in CMS when you are using an ASP-based solution. We will be covering the ASP.NET-based solution.
In a Web site, when an ASPX page runs, a Context instance is established by CMS using the intrinsic credentials and mode of the HttpRequest found in the query string. From that Context every other object can be immediately accessed. These interrelated objects do not need to be created in order to be used, because CMS will have already initialized and instantiated all the objects within the Context of the Posting or Channel we requested. The specific type of Context created by CMS on an ASP.NET Web site is a CmsHttpContext.
We cannot create an instance of CmsHttpContext, but we can get a handle to the instance that CMS created for our HttpRequest using the Current property. Since only one CmsHttpContext is allowed per running HttpRequest, Current either will return the instance that CMS created or it will create, initialize, and return a Context instance if it does not yet exist.
Unlike previous versions of CMS, the current release also allows for the creation of a Context in a stand-alone solution potentially outside the confines of IIS. Using the CmsApplicationContext class, we can instantiate a Context using the credentials of our choosing in the mode of our choosing. Although most of the objects in the model can be accessed in much the same way as they are within a CmsHttpContext, the concept of a current Posting and a current Channel don't make sense and therefore aren't available. Specific Channels and Postings can certainly be located and manipulated using the Searches property.
NOTE: The next chapter covers CmsHttpContext and CmsApplication Context in depth. The Searches property is covered in detail in Chapter 28.
Once we have a Context, we can access the objects in the object model. So, let's discuss what we have at our disposal.