5

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?

SpoiledTechie.com
  • 10,515
  • 23
  • 77
  • 100

6 Answers6

7

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

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

If you need more:

Request.Url.Scheme + "://" + Request.Url.Host + ":" + Request.Url.Port
Brian
  • 4,931
  • 3
  • 32
  • 55
5

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

John Rasch
  • 62,489
  • 19
  • 106
  • 139
5

Take a look at the VirtualPathUtility class.

Sean Bright
  • 118,630
  • 17
  • 138
  • 146
2

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
Community
  • 1
  • 1
Bob
  • 97,670
  • 29
  • 122
  • 130
  • 1
    the difference between ResolveUrl and ResolveClientUrl is that ResolveClientUrl returns a path relative to the current page, ResolveUrl returns a path relative to the site root: http://www.andornot.com/about/developerblog/2007/06/resolveurl-vs-resolveclienturl.aspx – Aaron Hoffman Apr 22 '09 at 16:37
0

Here's an article that explains the difference between the various ways to resolving paths in ASP.NET -

Different approaches for resolving URLs in ASP.NET

Rohit Agarwal
  • 4,269
  • 3
  • 27
  • 22
0

Here's what I use:

Response.Redirect(Response.ApplyAppPathModifier("~/default.aspx"))
Jared
  • 7,165
  • 6
  • 49
  • 52
  • is there a difference between using the Response.ApplyAppPathModifier() and Page.ResolveUrl(), in particular when dealing with MVC pages (not web forms)? – Thiago Silva Sep 22 '09 at 16:19
  • oh, and I mean not for Redirect, but rather for getting URLs (e.g. setting src attributes, etc). – Thiago Silva Sep 22 '09 at 16:20