Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Convert "~/default.aspx" to "http://www.website.com/default.aspx" C#?

Tags:

methods

c#

I know ASP.NET does this automatically, but for some reason I can't seem to find the method.

Help anyone? Just as the title says.

If I do a Response.Redirect("~/Default.aspx"), it works, but I don't want to redirect the site. I just want the full URL.

Can anyone help me out?

like image 942
SpoiledTechie.com Avatar asked Apr 22 '09 15:04

SpoiledTechie.com


4 Answers

For the "/#{path}/Default.aspx" part, use:

Page.ResolveUrl("~/Default.aspx")

If you need more:

Request.Url.Scheme + "://" + Request.Url.Host + ":" + Request.Url.Port
like image 121
Brian Avatar answered Nov 04 '22 03:11

Brian


In a web control, the method is ResolveUrl("~/Default.aspx")

like image 43
John Rasch Avatar answered Nov 04 '22 02:11

John Rasch


Take a look at the VirtualPathUtility class.

like image 26
Sean Bright Avatar answered Nov 04 '22 01:11

Sean Bright


There are at least three ways of doing this. I asked if there was any difference, but I didn't get any answer.

  1. Control.ResolveUrl
  2. Control.ResolveClientUrl
  3. VirtualPathUtility.ToAbsolute
like image 42
Bob Avatar answered Nov 04 '22 02:11

Bob