Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
376 views
Welcome To Ask or Share your Answers For Others

1 Answer

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...