Niversity: Abdul Majid Niazai
Niversity: Abdul Majid Niazai
Niversity: Abdul Majid Niazai
Asp.net
Abdul Majid Niazai
[email protected]
ASP.NET Web Pages - Folders
This chapter is about folders and folder paths.
Below is a typical folder structure for an ASP.NET web pages web site:
The physical structure for the "Images" folder at the website above might look
like this on a computer:
C:\Johnny\Documents\MyWebSites\Demo\Images
Virtual and Physical Names
A virtual path is shorthand to represent physical paths. If you use virtual paths, you can
move your pages to a different domain (or server) without having to update the paths.
URL https://www.hewade.com/html/html5_intro.asp
Server name Hewad
Virtual path /html/html5_intro.asp
Physical path C:\MyWebSites\hewad\html\html5_intro.asp
note
The root on a disk drive is written like C:\, but the root on a web site is /
(forward slash).
The virtual path of a web folder is (almost) never the same as the physical
folder.
In your code you will, reference both the physical path and the virtual path,
depending on what you are coding.
ASP.NET has 3 tools for working with folder paths: the ~ operator, the
Server.MapPath method, and the Href method
The ~ Operator
Just like _AppStart runs before your site starts, you can write code that
runs before any page in each folder.
For each folder in your web, you can add a file named _PageStart.
Typical use for _PageStart is setting the layout page for all pages in a
folder, or checking that a user is logged in before running a page.
How Does it Work?
Explaination
When a request comes in, ASP.NET checks whether _AppStart exists. If so, and this is the
first request to the site, _AppStart runs.
Then ASP.NET checks whether _PageStart exists. If so, _PageStart runs, before the
requested page.
If you include a call to RunPage() inside _PageStart you specify where you want the
requested page to run. If not, the _PageStart runs before the requested page.
End of Chapter 05