Get root path in ASP.NET without using Tilde ~
Mar 14
.NET, ASP.NET ASP.NET No Comments
As you probably know you can use the tilde sign (~) in ASP.NET to get the relative path of the root of your Web Site or Web Application. But unless using the Link Server Control or similar you may need some code to convert it to a correct url or get the absolute path.
Using a Server Control – example using the HyperLink Web Server Control
MyHyperLink.NavigateUrl = "~/Products/XYZ"
Using HttpRuntime.AppDomainAppVirtualPath
strAbsoluteUrl = HttpRuntime.AppDomainAppVirtualPath & "/Products/XYZ"
Using VirtualPathUtility.ToAbsolute
strAbsoluteUrl = VirtualPathUtility.ToAbsolute("~/Products/XYZ")

Recent Comments