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

I have an application page, added to a site collection. I open the page by the url: http://servername/sitecollection/_layout/sc/page.aspx

I have added some links, which should open the SAME Url with an additional query string. But it doesn't work. I've tried alot of methods, but all the links routes me to http://servername/_layout/sc/page.aspx.

So how can I programmaticly find the right url?

I've tried Http.Context, Request and so on, but one works. :\

So does anyone have an Idea?

Best Regards


PS: My system is SP2010 Standard Edition Service Pack 2.


Here are some of the Methods I have tried:

return SPContext.Current.Site.MakeFullUrl(SPContext.Current.Web.ServerRelativeUrl);

return SPContext.Current.Site.MakeFullUrl(SPContext.Current.Web.ServerRelativeUrl);

return HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Path);

return SPContext.Current.File.Url;

return "http://" + Request.ServerVariables["SERVER_NAME"] + Request.ServerVariables["URL"];
share|improve this question
Are you sure about links? Maybe it's realy link to servername/_layout/sc/page.aspx, but not to servername/sitecollection/_layout/sc/page.aspx ? – IAfanasov Dec 23 '11 at 12:24
The problem is that I open this page by the url with the site collection. – Smokefoot Dec 23 '11 at 12:58
up vote 4 down vote accepted

I prefer to use following:


First one for site collection relative url and the other one for site relative url.

share|improve this answer
Good point - this is much 'nicer'... – Bernd Rickenberg Dec 24 '11 at 13:04

You can simply use:


If you need the context of the current site in the application page, use:

SPContext.Current.Web.Url + "/_layout/sc/page.aspx"
share|improve this answer
Hey, ok that was easy... thought about an automatic solution but it hasn't worked. So your solution fits my problem. Thank you very much! Marry Christmas! – Smokefoot Dec 23 '11 at 14:02
Hope it does not throw an error when SPContext.Current.Web.Url results in "/". – Ashish Patel Dec 23 '11 at 15:07
no it doesn't. It fits the problem very well. – Smokefoot Dec 28 '11 at 15:53

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.