Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 检测I';我正在SharePoint中运行_.net_Sharepoint_Reflection_Sharepoint 2010 - Fatal编程技术网

.net 检测I';我正在SharePoint中运行

.net 检测I';我正在SharePoint中运行,.net,sharepoint,reflection,sharepoint-2010,.net,Sharepoint,Reflection,Sharepoint 2010,是否有办法让我的ASP.net应用程序知道它是否在SharePoint(2010)中运行,但不引用SharePoint程序集?(所以我不能只检查SPContext.Current是否为null) 我想知道是否可以获取按名称加载的所有程序集?因此,如果我看到我的AppDomain包含Microsoft.SharePoint程序集,那么我就知道我在SharePoint中 用例:程序集也在SharePoint外部运行,但引用SharePoint DLL需要部署它们(可能不是由于许可),或者在访问Sha

是否有办法让我的ASP.net应用程序知道它是否在SharePoint(2010)中运行,但不引用SharePoint程序集?(所以我不能只检查SPContext.Current是否为null)

我想知道是否可以获取按名称加载的所有程序集?因此,如果我看到我的AppDomain包含Microsoft.SharePoint程序集,那么我就知道我在SharePoint中

用例:程序集也在SharePoint外部运行,但引用SharePoint DLL需要部署它们(可能不是由于许可),或者在访问SharePoint方法时遇到异常


目前我使用条件编译,但我不想使用条件编译,而是想使用DI机制从两个类中选择一个,这取决于我是否在SharePoint中。

一种方法是检查当前进程(w3wp.exe)的命令行参数并查找“-ap”SharePoint内容应用池“。就我个人而言,我更喜欢您提到的方法(查找Microsoft.SharePoint.dll程序集)


未经测试,但这将对名为Microsoft.SharePoint的已加载程序集执行检查。

次要问题:its
AppDomain.CurrentDomain.GetAssemblys()…
还有两件事:。Any使用谓词,因此可以删除.Where。此外,AssemblyName是StartsWith,而不是==因为它是强名称<代码>AppDomain.CurrentDomain.GetAssemblys().Any(a=>a.FullName.StartWith(“Microsoft.Sharepoint”)这是我当前的方法。@Michael Stum,这就是我将其传递到AssemblyName构造函数的原因,因为MS建议不要手动解析FullName“不建议编写自己的代码来解析显示名称。相反,将显示名称传递给AssemblyName构造函数,该构造函数将对其进行解析并填充新AssemblyName的相应字段。“我认为答案中有一个输入错误-可能是
“Microsoft.SharePoint”
(大写P).对吗?@yellowblood:Quick google说你是对的,所以我会改变,但正如我所说的,我没有一个测试盒来确定。
bool isSharepoint =
     AppDomain
        .CurrentDomain
        .GetAssemblies()
        .Any(a => new AssemblyName(a.FullName).Name == "Microsoft.SharePoint");