ASP.NET Web Pages folder
This chapter provides information folders and folder path to knowledge.
In this chapter, you will learn:
- Physical and logical folder structure folder structure
- Virtual name and the physical name
- Web URL and Web path
Logical folder structure
The following are typical ASP.NET Web site folder structure:
- "Account" folder contains logon and security documents
- "App_Data" folder that contains the database and data files
- "Images" folder contains pictures
- "Scripts" folder contains the browser script
- "Shared" folder contains common files (such as the layout and style file)
Physical folder structure
In the site "Images" folder on the computer's physical folder structure might look like:
C: \ Documents \ MyWebSites \ Demo \ Images
Virtual name and the physical name
In the example above, for example:
The name of the virtual image of the site may be "Images / pic31.jpg".
Corresponding physical name is "C: \ Documents \ MyWebSites \ Demo \ Images \ pic31.jpg".
URL and path
URL is used to access the Web site files: http://www.w3cschool.cc/html/html-tutorial.html
URL corresponding to a physical file on the server: C: \ MyWebSites \ w3cschool \ html \ html-tutorial.html
Virtual path is the physical path of a shorthand representation. If you use a virtual path, when you change your domain or pages moved to other servers, you can not update path.
|Physical path||C: \ MyWebSites \ w3cschool \ html \ html-tutorial.html|
The root directory of the disk drive are written in C:, but the site's root directory is / (slash).
Virtual path to the Web folder is often not identical with the physical folder.
In your code, your code will need to decide to use physical paths and virtual paths.
ASP.NET folder path There are three tools: the ~ operator, Server.MapPath method and the Href method.
Use ~ operator, the virtual path specified in the programming code.
If you use the ~ operator migrate your site to a different location or a different folder, you can not change any of your code is:
var myStyleSheet = "~/styles/StyleSheet.css";
Server.MapPath method virtual path (/index.html) is converted into a physical path to the server understands (C: \ Documents \ MyWebSites \ Demo \ default.html).
When you need to open the data file on the server, you can use this method (only to provide a complete physical path to access data files):
var fileName = Server.MapPath(pathName);
In the next chapter of this tutorial, you'll learn more about reading (and writing) data file on the server knowledge.
Href method to convert the code path used to be understood that the path browser (browsers do not understand the ~ operator).
You can create a resource (such as image files and CSS files) path using the Href method.
Usually <a> in HTML, <img> and <link> element to use this method:
<!-- This creates a link to the CSS file. -->
<link rel="stylesheet" type="text/css" href="@Href(myStyleSheet)" />
<!-- Same as : -->
<link rel="stylesheet" type="text/css" href="/Shared/Site.css" />
Href method is a method WebPage object.