.NET Tip of The Day
Learn one new .NET trick every day
Быстрое пополнение счета телефона      Login or Join

How to create fully qualified URLs

With ASP.NET it's quite easy to get absolute path to a page by calling the VirtualPathUtility.ToAbsolute method. Getting absolute URL is not that obvious but still quite easy. Just combine request url with absolute path to your ASP.NET page:

string absolutePath = VirtualPathUtility.ToAbsolute("~/test/MyWebForm.aspx");

Uri newUri = new Uri(Request.Url, absolutePath);



1/18/2008

Comments:

NICE, Very Nice

JP 12/15/2008 11:21:35 PM

Uri newUri = new UriBuilder(Request.Url.Scheme, Request.Url.Host, Request.Url.Port, absolutePath, aQueryMaybe).Uri;

murki 1/12/2010 11:53:59 PM

Name
URL
E-mail
Provide your e-mail address to receive notification about new comments.
Message
HTML tags are not supported.
Please add 1 and 2 and type the answer here:
RSS .NET Tip of The Day
Subscribe to receive one tip from the .NET Tips and Tricks Community per day.
Previous Tips of The Day
The best of the .NET Tips & Tricks Community.
.NET Practitioners .NET Tips & Tricks Community
Every .NET practitioner has a trick up in their sleeve. This is the place to share it with other .NET people.
Submit a Tip
Discovered a new trick? Share it with others.
My Tips
Manage tips you authored.