This chapter introduces the global pages AppStart and PageStart.
Before the Web starts: _AppStart
Most of the server-side code is written in the personal web page. For example, if a web page contains an input form, the web page usually contains server-side code that reads the form data.
However, you can start code execution before the site starts by creating a page called _AppStart in the root of your site. If this page exists, ASP.NET will run this page first when other pages in the site are requested. Typical uses for
_AppStart are to start code and initialize global values (such as counters and global names).
Note 1: The file extension of _AppStart is consistent with your web page, such as: _AppStart.cshtml.
Note 2: _AppStart has an underscore prefix. Therefore, these files cannot be browsed directly.
Before every page: _PageStart
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 website, you can add a file named _PageStart.
How does it work?
The following diagram shows how it works:
When receiving a request, ASP.NET will first check whether _AppStart exists. If _AppStart exists and this is the first request received by the site, _AppStart is run.
Then ASP.NET checks whether _PageStart exists. If _PageStart exists, _PageStart is run before other requested pages.
You can call RunPage() in _PageStart to specify the running location of the requested page. Otherwise, by default, the requested page is run after _PageStart is run.
【Related recommendations】
1. ASP.NET free video tutorial
2. Share ASP.NET study notes (1) --WebPages Razor
3. Share ASP.NET study notes (2)--WebPages Introduction
4. Share ASP.NET study Notes (3) WebPages layout
5. Share ASP.NET study notes (4) Folder
The above is the detailed content of Share ASP.NET study notes (5) Global page AppStart and PageStart. For more information, please follow other related articles on the PHP Chinese website!