views:

46

answers:

2

I need to get the current absolute url of my site from inside an aspx page (no codebehind). I tried $SPUrl, but it get's converted into a relative url.

<asp:Literal runat="server" text="<% $SPUrl:~Site/mypage.aspx %>" />

results in "/mypage.aspx". It's important that I get the full absolute url starting with "http://".

<asp:Literal runat="server" text="<% $SPUrl:~SiteCollection/mypage.aspx %>" />

does the same. The goal is to get this url: "http://myspweb.com/mypage.aspx" as result.

A: 

You could use SPContext.Current.Site.Url to get the absolute url of the current site collection:

<%@ Import Namespace="Microsoft.SharePoint"%>
<!-- ... -->    
<%= SPContext.Current.Site.Url %>
Jason
A: 

Jason is correct on how to get the URL.

One thing to realize however about SharePoint is there may not be an actual "true" absolute site URL. With a SharePoint content database, you can extend the application to different IIS applications which have different web.configs, etc. Often people do this when they have an extranet for employees (Active Directory security) but will then want to allow customers in via Forms Based Authentication. That is one of the main reasons that SharePoint converts things to a relative URL.

John Ptacek