{"id":3213,"date":"2010-12-19T05:38:37","date_gmt":"2010-12-19T05:38:37","guid":{"rendered":"https:\/\/test.simple-talk.com\/uncategorized\/resolving-an-app-relative-url-without-a-page-object-reference\/"},"modified":"2016-07-28T10:50:16","modified_gmt":"2016-07-28T10:50:16","slug":"resolving-an-app-relative-url-without-a-page-object-reference","status":"publish","type":"post","link":"https:\/\/www.red-gate.com\/simple-talk\/blogs\/resolving-an-app-relative-url-without-a-page-object-reference\/","title":{"rendered":"Resolving an App-Relative URL without a Page Object Reference"},"content":{"rendered":"<p>If you&#8217;ve worked with ASP.NET before then you&#8217;ve almost certainly seen an application-relative URL like ~\/SomeFolder\/SomePage.aspx.&#160; The tilde at the beginning is a stand in for the application path, and it can easily be resolved using the <strong>Page<\/strong> object&#8217;s <strong>ResolveUrl<\/strong> method:<\/p>\n<p>string url = Page.ResolveUrl(&#8220;~\/SomeFolder\/SomePage.aspx&#8221;);<\/p>\n<p>There are times, however, when you don&#8217;t have a page object available and you need to resolve an application relative URL.&#160; Assuming you have an <strong>HttpContext<\/strong> object available, the following method will accomplish just that:<\/p>\n<p>public static string ResolveAppRelativeUrl(string url)   <br \/>{    <br \/>&#160;&#160;&#160;&#160; return url.Replace(&#8220;~&#8221;, System.Web.HttpContext.Current.Request.ApplicationPath);    <br \/>}<\/p>\n<p>It just replaces the tilde with the application path, which is essentially all the <strong>ResolveUrl<\/strong> method does.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you&#8217;ve worked with ASP.NET before then you&#8217;ve almost certainly seen an application-relative URL like ~\/SomeFolder\/SomePage.aspx.&#160; The tilde at the beginning is a stand in for the application path, and it can easily be resolved using the Page object&#8217;s ResolveUrl method: string url = Page.ResolveUrl(&#8220;~\/SomeFolder\/SomePage.aspx&#8221;); There are times, however, when you don&#8217;t have a page&#8230;&hellip;<\/p>\n","protected":false},"author":46738,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[2],"tags":[],"coauthors":[],"class_list":["post-3213","post","type-post","status-publish","format-standard","hentry","category-blogs"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/3213","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/users\/46738"}],"replies":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/comments?post=3213"}],"version-history":[{"count":2,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/3213\/revisions"}],"predecessor-version":[{"id":41978,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/3213\/revisions\/41978"}],"wp:attachment":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/media?parent=3213"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/categories?post=3213"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/tags?post=3213"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/coauthors?post=3213"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}