tags:

views:

426

answers:

3

I am trying to find away to determine a pages url from the page object. It seems you can only get the path of the current context.

+2  A: 

A page can have several urls. For example, I have a server running at home and the site's url is different depending on where I check it from. When I'm at home I just use the internal server name so that the traffic never leaves my home network. When I'm elsewhere I have to use the dyndns.org -based url. I could also configure several different sites to all point to the same place. The point is that this information is not tied to your page's class type, or even a specific instance.

Therefore, the URL of a page can only be determined on a per-request basis, and sure enough you can get it by looking at Request.Url

Joel Coehoorn
the per request thing is my problem. I can always get it in context but I would like just to get the script path either virtually (for web) or physically (on the disk). I don't actually need the full url just the directory and script location
My advise is to add that path as a parameter for whatever function needs it, and change how you call it.
Joel Coehoorn
Hmm... I take part of it back. It's per session rather than per-request. The logic involved (and proposed solution) still apply, however.
Joel Coehoorn
A: 

Hopefully one of these will help you.

Understanding Paths in ASP.NET

Expression - Evaluation

this.TemplateSourceDirectory - /informit/subdir

Request.MapPath("log.txt") - c:\mywebdirs\informit\subdir\log.txt

this.MapPathSecure("log.txt") - c:\mywebdirs\informit\subdir\log.txt

Request.Path - /informit/subdir/pathsample.aspx/extra

Request.FilePath - /informit/subdir/pathsample.aspx

Request.CurrentExecutionFilePath - /informit/subdir/pathsample.aspx

Request.PathInfo - /extra

Request.PhysicalPath - c:\mywebdirs\informit\subdir\pathsample.aspx

Request.PhysicalApplicationPath - c:\mywebdirs\informit\

Request.ApplicationPath - /informit

Request.Url - http://localhost/informit/subdir/client.aspx/extra

Request.RawUrl - /informit/subdir/pathsample.aspx/extra

Response.ApplyAppPathModifier("foo.aspx") - /informit/subdir/foo.aspx

this.ResolveUrl("~/client.aspx") - /informit/pathsample.aspx

Glennular
A: 

It should be available via

string currentUrl = Page.Request.Url.ToString();

iZ