0

We have created web application.

Within this we created 2 site collection: Site collection 1 - http://pcname:3333/

Site collection 2 - http://pcname:3333/sites/sc2

Within each site collection we created 3 webs.

  1. How to get the root site colelction URL (not root web of sitecollection) via SSOM

  2. How to get the root site colelction URL via ECMA (say on masterpage)

1

Using C# (server-side):

SPSite siteCollection = SPContext.Current.Web.Site;
var rootSiteCollection = siteCollection.WebApplication.Sites[0].Url;

If you have alternate URLs, then use 'AlternateUrls'

On the client side, you could use plain old javascript

var winLoc = window.location;
var siteUrl = winLoc.protocol + '//' + winLoc.host + (winLoc.port ? ':' + winLoc.port : '');
window.console && console.log(siteUrl);
| improve this answer | |
1

In addition, for client javascript, _spPageContextInfo is your friend.

http://blah.winsmarts.com/2013-2-_spPageContextInfo_is_your_new_best_friend.aspx

| improve this answer | |

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.