Use LINQ To Get Central Administration Web Applications
I needed a quick and dirty way to go through the SPWebService.AdministrationService to get a collection SPWebService.WebApplications and then test whether the SPWebApplication is the Central Administration application. To do this you need to use the SPWebApplication.IsAdministrationWebApplication boolean property. To keep things succinct you can just chain a LINQ query to return the representative SPSite of the desired administrative SPWebApplication. Consider the following RetrieveAdminApplication method that is consuming a SPContext object as a parameter:
- public static SPSite RetrieveAdminApplication(SPContext context)
- return SPWebService.AdministrationService.WebApplications.Cast().
- Where(application => application.IsAdministrationWebApplication).FirstOrDefault().
This is probably not ideal, but will work!