SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there an easy way to get just the web application URL in SharePoint, for example, SPWEbApplication has the following property spwebapplication.sites that would return URL's of all the site collections, but not of the root URL that they all contain. So I could return this:


but not this:


Is there an easy way to get http://thiswebapplication without any parsing, using the SharePoint or built in ASP.NET objects?

share|improve this question
up vote 9 down vote accepted

Remember that SharePoint web applications can have multiple URLs since they can be extended onto different IIS websites e.g. and

If you're looking to get the URL for the default zone (either with a web app which has been extended or not), you can use:

share|improve this answer

From the SPWebApplication object you have access to AlternateURLs which will provide the collection of URLs as specified in the Alternate Access Mappings.

share|improve this answer


This is also easily accessed by PowerShell;

$sites = Get-SPSite | Where-Object {$_.Url -like "*portal*"}
 foreach ($site in $sites) {
  Write-Host "Site is SPSite Url=$site"
share|improve this answer
in Powershell, it's abstracted enough that the SPWebApplication object (thus it would seem, not the same SPWebApplication object used in .net api) actually has a Url property – Code Jockey Nov 12 '15 at 18:33

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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