Monday, 29 October 2012

ASP.net Application and Request Paths Explained

I want to do something simple. Using the current request, obtain the absolute url of the site root and then add another file path to it. For example, taking the request which might be http://www.example.com/myapp/directory/current.aspx, I want to obtain http://www.example.com/myapp and then I want to add on e.g. /otherdir/otherfile.aspx to be used in a password reset email.
Anyway, not really doable out-of-the box but then I realised what I really wanted was a reference for all the path relevant elements of the request object so I could work out which bits I needed to glue together. Well, here it is:

HttpRequest
->ApplicationPath = "/MyApp"
->AppRelativeCurrentExecutionFilePath = "~/SubDir/Current.aspx"
->CurrentExecutionFilePath = "/MyApp/SubDir/Current.aspx"
->CurrentExecutionFilePathExtension = ".aspx"
->FilePath= "/MyApp/SubDir/Current.aspx"
->Path= "/MyApp/SubDir/Current.aspx"
->PhysicalApplicationPath= "C:\\inetpub\\wwwroot\\MyApp\\"
->PhysicalPath= "C:\\inetpub\\wwwroot\\MyApp\\SubDir\\Current.aspx"
->RawUrl= "/MyApp/SubDir/Current.aspx"
->Url
->->AbsolutePath = "/MyApp/SubDir/Current.aspx"
->->AbsoluteUri = "http://localhost/MyApp/SubDir/Current.aspx"
->->Authority = "localhost"
->->DnsSafeHost = "localhost"
->->Host = "localhost"
->->LocalPath = "/MyApp/SubDir/Current.aspx"
->->OriginalString = "http://localhost:80/MyApp/SubDir/Current.aspx"
->->PathAndQuery = "/MyApp/SubDir/Current.aspx"
->->Port = 80
->->Scheme = "http"
->->Segments
->->->[0] = "/"
->->->[1] = "MyApp/"
->->->[2] = "SubDir/"
->->->[3] = "Current.aspx"
->UserHostAddress= "127.0.0.1"
->UserHostName= "127.0.0.1"
Post a Comment