I have created my web application on http protocol, http://SPExample.com and deploy .wsp solution on it. My application runs on both protocols, i.e http://SPExample.com and on https://SPExample.com. On page load function i have written following code. If i access my application on https protocol, then under Page_Load, what value RootUrl variable will contain? http://SPExample.com or https://SPExample.com?

RootUrl = SPContext.Current.Site.WebApplication.GetAbsoluteUrl();
  • Debug and see what shows up – Nadeem Yousuf Mar 21 '15 at 15:40

The SPContext.Current.Site.WebApplication.GetAbsoluteUrl() will return the URL based on the protocol you are accessing. For example, if you are using http://SPExample.com it will return http://SPExample.com, likewise, https://SPExample.com will return https://SPExample.com. However, as Nadeem mentioned, the best way to verify would be to debug and examine the RootUrl value.

If you are unaware how to debug within a local SharePoint instance, you'll want to set a breakpoint on the the code, and attach your Visual Studio instance to the W3WP.exe worker process. Once the code hits related code, it will let you examine the RootUrl value.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.