tags:

views:

201

answers:

6

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?

+4  A: 

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

John Rasch
+4  A: 

Take a look at the VirtualPathUtility class.

Sean Bright
+7  A: 

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
+2  A: 

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
Bob
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
A: 

Here's what I use:

Response.Redirect(Response.ApplyAppPathModifier("~/default.aspx"))
Jared
is there a difference between using the Response.ApplyAppPathModifier() and Page.ResolveUrl(), in particular when dealing with MVC pages (not web forms)?
Thiago Silva
oh, and I mean not for Redirect, but rather for getting URLs (e.g. setting src attributes, etc).
Thiago Silva
A: 

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