Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I want to get the current page absolute url in sharepoint.. I'm using:

this.Page.Request.Url.ToString()

But for:

http://e-albania.tirana.bz:6002/sites/ealbania02/_layouts/IISNewsBox/news_view.aspx

it returns

http://e-albania.tirana.bz:6002/_layouts/IISNewsBox/news_view.aspx

Maybe cause layouts folder is the same for all the web applications.. How do I get the correct url?

share|improve this question
1  
Have you tried Page.Request.RawUrl? –  Daniel Ziga Sep 17 '12 at 8:34
    
THANK YOU SO MUCH. RawUrl solved the question :) –  MIlena Sep 17 '12 at 9:15

3 Answers 3

up vote 6 down vote accepted

Code below should do the trick

Page.Request.RawUrl
share|improve this answer
    
Great! Though it only gives you the relative URL without the http://domain/ part –  Dennis G Sep 27 '12 at 16:36

HttpContext.Current.Request.Url

or

http://stackoverflow.com/questions/9701309/get-app-relative-url-from-request-url-absolutepath

or

SPSite.MakeFullUrl()

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spsite.makefullurl.aspx

an example is:

using(SPSite site = new SPSite("http://e-albania.tirana.bz"))
{     using(SPWeb web = site.OpenWeb())
    {
      string absoluteURL = site.MakeFullUrl(this.Page.Request.Url.ToString());
    }
}

hope it helps :)

share|improve this answer
    
The time-battle forced you to update the answer? :) In any case very nice. +1 –  eirikb Sep 17 '12 at 9:03
    
well what can i say it a race against the time and I wanted to make sure he had a selection to choose from instead of HttpContext.Current.Request.Url lol. –  ali Sharepoint Sep 17 '12 at 9:07
    
Thanx but I don't know why HttpContext.Current.Request.Url doesn't work, instead Page.Request.RawUrl did it perfectly. –  MIlena Sep 17 '12 at 9:21

Try to use System.Web.HttpContext.Current.Request.Url

It should give you the current pages url.

share|improve this answer
    
it doesn't give you the url including subsites - maybe sharepoints custom iis pipeline at work –  Dennis G Sep 27 '12 at 16:36

Your Answer

 
discard

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.