[Asp.net] absolute path and relative path, asp.net absolute path

Source: Internet
Author: User

[Asp.net] absolute path and relative path, asp.net absolute path
Directory

Absolute path

Relative Path

Summary

Absolute path

The absolute path is the real path of the files or directories on your home page on the hard disk. For example, E: \ New Concept English second course. The directory path based on the Web site root directory. The reason for this is absolute: When all webpages reference the same file, the paths used are the same.

1 "-- represents the root directory, absolute path. 2 For example, <a href = "/abc"> text </a> or  3 "D: /abc/"-- represents the root directory, absolute path.

 

Relative Path

The directory path is created based on the location of the webpage that references the file. Therefore, when the web pages stored in different directories reference the same file, the paths used are different, so they are called relative.

The following are the special symbols used to create a path and their meanings.

1 "." -- indicates the current directory, relative path. 2 3 For example: <a href = ". /abc "> text </a> or  4 5 ".. "-- indicates the relative path of the last directory. 6 7 For example: <a href = ".. /abc "> text </a> or  8 ".. /.. /"-- indicates the directory of the previous directory and the relative path. 9 10 For example: 

When using relative paths, we use the symbol "." To represent the current directory, and the symbol "." To represent the parent directory of the current directory.

/Is the path Separator of hypertext protocol. All the paths displayed in the browser are separated by "/". It generally represents the virtual path.

In common program code, "\" indicates the file path separator. It generally refers to the physical path.

./Indicates that it is in the current path,

../Indicates the path under the upper-level path of the current path.

~ /Indicates the root directory of the current website.

And/and \ are worth it!

There are two major systems for expressing paths:
1. In windows, the file location is indicated by the Backslash "\", for example, E: \ New Concept English second course.

2. network path, such as http://www. I .cnblogs.com/EditPosts.aspx.

Note: The difference between/in the path and the backslash is also the network path used in the ftp operation. If \ is used, it cannot be parsed. previously in the project, I have suffered losses in this respect.

Summary

~ /In the runat = server control, it is automatically parsed as the value of Request. ApplicationPath, which is the directory of the current application-level Program (used in the server control ).

/: Indicates the current directory.

../Indicates the previous directory.

/Indicates the root directory.


Aspnet relative path to absolute path

Server. MapPath ("relative path ~~
Example:
Server. MapPath ("/") Return Path: D: \ www
Server. MapPath ("~ /") Return Path: D: \ www
Server. MapPath ("/images") Return Path: D: \ www \ images

How does ASPNET convert relative paths to absolute paths?

Of course, this is not the case! For example, an image folder in the website project, ImageBag, can use Server in the program. mapPath (@ "\ ImageBag"); in this way, the path of this folder is obtained. After the website is uploaded to the server, you are placed on the F disk. The path is F... the same is true for others. you can save the image name. For example, you do not need to save the path for myimg.jpg .. /ImageBag/myimg.jpg is displayed on the web page. You can directly use the Server object, but you need to reference a namespace System elsewhere in the class. web. httpContext. current. server ..... this namespace

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.