The best Global file ASP.NET Web Pages Tutorial In 2024, In this tutorial you can learn Before starting Web: _AppStart,Before every page: _PageStart,How does it work?,
This chapter describes the global page AppStart and PageStart.
Most server-side code is written in a personal web page inside. For example, if the page contains input form, then this website to read form data usually contain server-side code.
However, you can create a page called _AppStart at the root of your site, this site prior to launch code execution can be started. If there is this page, ASP.NET will be at the site in the other pages of the requested priority to run this page.
Typical uses _AppStart the startup code and initialize the global value (such as counters and global name).
Note 1: _AppStart file extension is consistent, for example, your page: _AppStart.cshtml.
Note 2: _AppStart underlined prefix. Therefore, it can not directly browse.
Code running as before _AppStart before your site will start running, you can write in each folder of any page.
For your site each folder, you can add a file named _PageStart of.
_PageStart Typical use is to set the page layout of a folder all pages, or a page before running checks whether the user has logged in.
The figure below shows how it works:
Upon receiving a request, ASP.NET first checks _AppStart exists. If _AppStart site exists and this is the first request received, run _AppStart.
Then ASP.NET checks _PageStart exists. If _PageStart exists, before other page is requested to run the first run _PageStart.
You can call RunPage in _PageStart in () is requested to specify the operative position of the page. Otherwise, by default, the requested page is _PageStart was only run after run.