Brains Engineering - Il Blog

Path Mapping: Absolute, relative, local or complete URL

scritto da giox 26/03/2009 21.28.35

There are more than 30 methods in ASP.NET classes that deal with paths and/or URLs. Many developers coming from traditional ASP tend to stick with the methods they know from ASP (which are still there), but there are many other useful methods that can save you a lot of time and headache.

 

Let’s take a look at everything from virtual to physical path mapping to root path reference syntax.

 

Input: http://localhost:2036/engineering/Tmp/Test.aspx?q=parameter#fragment

Some HttpRequest path and URL properties:

 

Request.ApplicationPath:/engineering

Request.CurrentExecutionFilePath:/engineering/Tmp/Test.aspx

Request.FilePath:/engineering/Tmp/Test.aspx

Request.Path:/engineering/Tmp/Test.aspx

Request.PathInfo:

Request.PhysicalApplicationPath:D:\Inetpub\wwwroot\brains\engineering\

Request.QueryString:/engineering/Tmp/Test.aspx?q=parameter

Request.Url.AbsolutePath:/engineering/Tmp/Test.aspx

Request.Url.AbsoluteUri:http://localhost:2036/engineering/Tmp/Test.aspx?q=parameter

Request.Url.Fragment:

Request.Url.Host:localhost

Request.Url.Authority:localhost:2036

Request.Url.LocalPath:/engineering/Tmp/Test.aspx

Request.Url.PathAndQuery:/engineering/Tmp/Test.aspx?q=parameter

Request.Url.Port:2036

Request.Url.Query:?q=parameter

Request.Url.Scheme:http

Request.Url.Segments:/engineering/Tmp/Test.aspx

Now let’s take a look at the Server.MapPath() method:

As everyone knows MapPath() converts a virtual path into a physical path.

 

// This will locate the Example.xml file in the App_Data folder.

string tmp = Server.MapPath("~/App_Data/Example.xml");

 

Performance and Optimization:

MapPath performance is over 1000 times slower than a simple string append. Therefore, it could be worthwhile to cache the paths.

Correntemente valutato 5.0 da 1 utenti

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Categorie: ASP.Net

Post correlati

Commenti

06/06/2011 11.04.32

casino online

wow! che l'articolo di cool! grazie =)

casino online it

14/02/2012 5.58.47

web hosting

This article comes from the articles is very beautiful, he also speaks on the subject of MATZA It's really a great article

web hosting in

Aggiungi commento


(Visualizza la tua icona Gravatar)  

  Country flag

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Anteprima

20/05/2012 1.53.31

Cerca



Calendario

<<  maggio 2012  >>
lumamegivesado
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910

© Copyright 2012

Sign in