Many people are confused about the relative path and absolute path. I have sorted it out and hope it will help you understand it.
++ ++
1.Request. applicationpath->Current application directory
In JSP, applicationpath refers to the current application (ApplicationProgramIn ASP. NET.
For example, two web application domain names on my server are mockte.com, one mapped to the directory mockte.com/1/ and the other to the http://mockte.com/2/.
Then mockte.com/1/#the applicationpath of the first application is the same as mockte.com/2/#applicationpath of the second application.
2.Request. filepath->Virtual directory corresponding to IIS
Such as URL http://mockte.com/1/index.html/pathinfo
Filepath =/1/index.html
3.Request. Path->The Virtual Path of the current request.
PATH is the concatenation of filepath and pathinfo. Example: URL http://mockte.com/1/index.html/pathinfo
Then Path =/1/index.html/pathinfo
4.Request. mappath (string URL)->Map URLs to virtual directories on IIS
This directory is relative to the application root directory.
Compared with server. mappath, paths such as C:/are not included.
It can be understood as a relative path (the server. mappath in comparison is an absolute path)
5.Server. mappath (string URL)->Map a URL to a physical path on the server
For example, http://mockte.com/1/index.html suppose your application is in C:/IIS/mysite
C:/IIS/mysite/1/index.html
// Convert local paths to relative URLs
Private String Urlconvertor ( String Imagesurl1)
{
String Tmprootdir = Server. mappath (system. Web. httpcontext. Current. Request. applicationpath. tostring ()); // Get the program root directory
String Imagesurl2 = Imagesurl1.replace (tmprootdir, "" ); // Convert to relative path
Imagesurl2 = Imagesurl2.replace ( @" \ " , @" / " );
// Imagesurl2 = imagesurl2.replace (@ "aspx_uc /",@"");
Return Imagesurl2;
}
// Convert the relative path to the local physical path of the server
Private String Urlconvertorlocal ( String Imagesurl1)
{
String Tmprootdir = Server. mappath (system. Web. httpcontext. Current. Request. applicationpath. tostring ()); // Get the program root directory
String Imagesurl2 = Tmprootdir + Imagesurl1.replace ( @" / " , @" \ " ); // Convert to absolute path
Return Imagesurl2;
}
1. filepath = "/logs/abc.txt" is considered as the root directory, that is, the drive letter where the webpage file is located. The default disk is drive C. Here, this path is interpreted as "C: \ logs \ abc.txt"
2. Use filepath = "~ /Logs/abc.txt ", which is considered as the Server Directory
3. Use filepath = "./logs/abc.txt", still under the Server Directory
++ ++