简体   繁体   English

如何让我的webpart检测它是否托管在Sharepoint或vanilla ASP .Net中?

[英]How do i have my webpart detect whether it is hosted in Sharepoint or vanilla ASP .Net?

I have a suite of webpart controls that I maintain and develop for our main Sharepoint offerings. 我有一套webpart控件,我为我们的主要Sharepoint产品维护和开发。 I also have an Asp .Net website which acts as a test suite for selenium scripts and unit tests. 我还有一个Asp .Net网站,作为selenium脚本和单元测试的测试套件。

How can I determine from the web part code server code whether the control is currently being hosted in a Sharepoint page or whether the webpart is being hosted on a normal ASP .Net page? 如何从Web部件代码服务器代码确定控件当前是否在Sharepoint页面中托管,或者webpart是否托管在普通的ASP .Net页面上? I'm looking to prepopulate some of the webpart properties with defaults but only when they exist in the ASP .Net page environment. 我希望使用默认值预填充一些webpart属性,但仅限于它们存在于ASP .Net页面环境中。

if(this.WebPartManager.GetType()。Name ==“SPWebPartManager”){// SharePoint} else {// Not SharePoint}

您可以测试SPContext.Current.Web为null

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM