Detect if I'm running in SharePoint

Is there a way for my ASP.net application to find out if it works in SharePoint (2010), but without referring to the SharePoint builds? (Therefore, I cannot just check if SPContext.Current is null).

I wonder if it is possible to get all the assemblies that are loaded by name? Therefore, if I see that my AppDomain contains a Microsoft.SharePoint assembly, I know that I am in SharePoint.

Use case. The assembly is done outside of SharePoint, but linking to the SharePoint DLLs requires deploying them (possibly due to licensing) or getting exceptions when accessing the SharePoint method.

I am currently using conditional compilation, but I would like to get away from it and use the DI mechanism to select one of the two classes, depending on whether I am in SharePoint.

+6
source share
2 answers
bool isSharepoint = AppDomain .CurrentDomain .GetAssemblies() .Any(a => new AssemblyName(a.FullName).Name == "Microsoft.SharePoint"); 

Not completed, but it will check for downloaded assemblies whose name was Microsoft.SharePoint.

+9
source

One way to check the command line options of your current process (w3wp.exe) is to find the β€œ-ap" SharePoint Content AppPool. Personally, I prefer the method you mentioned (looking for Microsoft.SharePoint. Dll).

+1
source

Source: https://habr.com/ru/post/889732/


All Articles