简体   繁体   中英

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. I also have an Asp .Net website which acts as a test suite for selenium scripts and unit tests.

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? I'm looking to prepopulate some of the webpart properties with defaults but only when they exist in the ASP .Net page environment.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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