I always encounter Path Problems During website development and sometimes cannot understand them. After debugging, you always know the path of the application and how to obtain the path. In the face of this half-known problem, I am going to write these questions to give myself a long memory.
1. Start with several methods provided in C:
// Return the physical file path corresponding to the specified virtual path on the Web Server
Response. Write (server. mappath ("~ "));
Response. Write ("</BR> ");
// Obtain the root path of the virtual application of ASP. NET applications on the server
Response. Write (request. applicationpath );
Response. Write ("</BR> ");
// Obtain the virtual path of the current request
Response. Write (request. currentexecutionfilepath );
Response. Write ("</BR> ");
// Obtain the virtual path of the current request
Response. Write (request. filepath );
Response. Write ("</BR> ");
// Obtain the physical file system path of the root directory of the currently running server application
Response. Write (request. physicalapplicationpath );
Response. Write ("</BR> ");
// Obtain the physical file system path corresponding to the requested URL
Response. Write (request. physicalpath); The default. aspx result of the website is shown in the right figure:
The differences between the above methods are shown in the upper right corner. 2. Start with some symbols:
(1 ),~ "~ "Represents the virtual root directory of the Web application; the relative virtual path. (2 ),~ . (3 ),~ \ Same as (4) And/"/" represent the web application's and directory, and the relative representation of the physical path. That is, the absolute virtual path (5 ),. /". /"indicates the current directory (6 ),.. /The Directory (7) and \ are the same as "/" (8 ),. \ and ". /"is the same as (9) and has no current directory
3. Some examples:
in the preceding three examples, the image is correctly displayed. Indicates the current directory. Response. Write (" ");
Response. Write (" ");
Response. Write (" ");
Result:
File: // E:/job/zdssttask/website1/2009-01/01 -16-1.png
File: // E:/job/zdssttask/website1/2009-01/01 -16-1.png
Http: // localhost: 1738/website1/2009-01/01 -16-1.png in IIS, "\" and "/" can achieve the same effect, that is, there is no problem with the explanation of IIS. However, there may be problems when printing or writing the background page. "\" Is an escape character. To print "\", "\" is required.
Next let's take a look at the path of the motherboard page:
When selecting test. aspx, the motherboard can be as follows:
Internal motherboard:
Masterpagefile = "~ /2009-01/masterpage. Master"
Masterpagefile = "2009-01/masterpage. Master"
Same directory:
In masterpagefile = "masterpage. Master", default. aspx selects the motherboard as follows:
Upper-level directory:
Masterpagefile = "~ /Masterpage. Master"
Masterpagefile = "../masterpage. Master"
Same directory:
Masterpagefile = "~ /2009-01/masterpage. Master"
Masterpagefile = "masterpage. Master"
<Asp: Image id = "image1" runat = "server" imageurl = "~ /2009-01/01 -16-2.png "/>
This is the image control on the server side, the referenced imageurl and the SRC path marked with IMG. However, the image control can find the correct path, but the IMG cannot.
Http: // localhost: 1738/website1/2009-01/01 -16-2.png
Http: // localhost: 1738/website1 /~ /2009-01/01 -16-2.png
Sometimes we need to make a difference.
Reference here: http://www.cnblogs.com/stonespawn/archive/2009/01/16/1376900.html
Let's take a look at some tips for configuring the ACCESS database path in Web. config:
1. It is certainly no problem to configure the following absolute physical path.
<Deleetask>
<Add key = "oledbconnectionstring" value = "provider = Microsoft. Jet. oledb.4.0; Data
Source = E: \ WEB \ app_data \ data. mdb) "> </Add>
</Appsettings>
2. Configure the following path.
<Deleetask>
<Add key = "oledbconnectionstring" value = "provider = Microsoft. Jet. oledb.4.0; Data
Source = "~ /App_data/mydata. mdb) "> </Add>
</Appsettings>
This will cause: 'C: \ windows \ system32 \~ \ App_data \ data. mdb 'is not a valid path.
3. But what follows is OK.
<Deleetask>
<Add key = "sqlconnstring" value = "provider = Microsoft. Jet. oledb.4.0; Data Source ="/>
<Add key = "dbpath" value = "~ /App_data/mydata. mdb "/>
</Appsettings>