May 12, 2021 ASP.NET
This chapter describes the knowledge of folders and folder paths.
In ASP.NET Web Pages, there are two folder structures: logical folder structure and physical folder structure.
In this chapter, you'll learn:
Here is a ASP.NET site folder structure:
The physical folder structure of the "Images" folder on your computer in the above Web site might be as follows:
C:\Documents\MyWebSites\Demo\Images
Take the example above:
The virtual name of the site image may be "Images/pic31 .jpg".
The corresponding physical name is "C:\Documents\MyWebSites\Demo\Images\pic31.jpg."
The URL is used to access files in the Web site: /www.w3cschool.cn/html/html-tutorial.html
The URL corresponds to the physical file on the server: C: s/MyWebSites/w3cschool?html-tutorial.html
A virtual path is a short-form representing a physical path. If you use a virtual path, you don't have to update the path when you change the domain name or move your page to another server.
Url | www.w3cschool.cn/html/html-tutorial.html |
The name of the server | w3cschool |
The virtual path | /html/html-tutorial.html |
The physical path | C:\MyWebSites\w3cschool\html\html-tutorial.html |
The root of the disk drive is written as follows C: , but the root of the web site is / (slash).
The virtual path of a Web folder is usually different from that of a physical folder.
In your code, decide to use physical and virtual paths based on your encoding needs.
ASP.NET folder paths have three tools: the operator, the Server.MapPath method, and the Href method.
The virtual path is specified in the programming code using the operator.
If you use the operator, you can move your site to a different folder or location without changing any of your code:
The Server.MapPath method converts the virtual path (/index.html) into a physical path that the server can understand (C: . . . Documents . . . MyWebSites ..html .
You can use this method when you need to open a data file on the server (data files can only be accessed by providing a complete physical path):
In the next chapter of this tutorial, you'll learn more about reading (and writing) data files on the server.
The Href method converts the path used in the code into a path that the browser can understand (the browser does not understand the operator).
You can use the Href method to create paths to resources such as image files and CSS files.
This method is typically used in elements of HTML:
The Href method is one way for WebPage objects.