Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting full URL from URL with tilde(~) sign

Tags:

c#

asp.net

I am trying to get a typical asp.net url starting with the tilde sign ('~') to parse into a full exact url starting with "http:"

I have this string "~/PageB.aspx"

And i want to make it become "http://myServer.com/PageB.aspx"

I know there is several methods to parse urls and get different paths of server and application and such. I have tried several but not gotten the result i want.

like image 764
Daarwin Avatar asked Feb 01 '12 07:02

Daarwin


People also ask

What does a tilde (~) in a URL indicate?

A tilde in a URL usually is followed by a user name and indicates that the files below that URL come from that user's home directory.

Is tilde url safe?

In particular, tilde and some other characters have now been declared as "safe", thereby not requiring encoding. However, the encoded notation is still a valid alternative and works more reliably.


1 Answers

Try out

System.Web.VirtualPathUtility.ToAbsolute("yourRelativePath");  

There are various ways that are available in ASP.NET that we can use to resolve relative paths to a resource on the server-side and making it available on the client-side. I know of 4 ways -

 1) Request.ApplicationPath  2) System.Web.VirtualPathUtility  3) Page.ResolveUrl  4) Page.ResolveClientUrl 

Good article : Different approaches for resolving URLs in ASP.NET

like image 62
Pranay Rana Avatar answered Oct 03 '22 04:10

Pranay Rana