ASP. NET Web Pages-Global Pages, asp. netpages
Before starting the Web: _ AppStart
Most server-side code is written on an independent webpage. For example, if a webpage contains an input form, the webpage usually contains the server code used to read data.
However, by creating a page named _ AppStart in the root directory of the site, you can run the startup code before the site starts ). If the page exists, ASP. NET runs the page before any page in the site is requested.
Usually _ AppStart is used to initialize code and global values, such as counters and global names.
NOTE 1: The file extension of _ AppStart should be the same as that of the webpage, for example, _ AppStart. cshtml.
NOTE 2: _ AppStart has an underline prefix. Therefore, you cannot directly view the file.
Before each page: _ PageStart
Just like running _ AppStart before the site starts, you can run code before any page in each folder.
For each folder on the web, you can add a file named _ PageStart.
Usually _ PageStart is used to set layout files for all pages in the folder, or to check user logon before running the page.
How to work?
The following shows how it works:
When the request arrives, ASP. NET checks whether _ AppStart exists. If it exists and is the first request to the site, run _ AppStart.
Then ASP. NET checks whether _ PageStart exists. If yes, run _ PageStart before the requested page.
If you reference a call to RunPage () in _ PageStart, you can specify where to run the requested page. Otherwise, _ PageStart runs before the requested page.