Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

ASP.NET Web Pages global page


May 12, 2021 ASP.NET


Table of contents


ASP.NET Web Pages - Global Page


This chapter describes the global page AppStart and PageStart.


Before the web starts: _AppStart

Most server-side code is written on a personal Web page. For example, if a Web page contains an input form, the Page typically contains server-side code to read the form data.

However, you can start code execution before the site starts by creating a page called _AppStart at the root of your site. If this page exists, ASP.NET will run the page first when other pages in the site are requested.

_AppStart typical use of a computer is to start code and initialize global values, such as counters and global names.

Note 1: _AppStart file extension 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 each page: _PageStart

Just _AppStart runs before your site starts, you can write code that runs before any page in each folder.

For each folder in your site, you can add a file called _PageStart file.

_PageStart typical use of a page is to set up layout pages for all pages in a folder, or to check that the user is signed in before running a page.


How does it work?

The following image shows how it works:

ASP.NET Web Pages global page

When a request is received, the ASP.NET first checks for _AppStart existence. If _AppStart exists and this is the first request received by the site, run _AppStart.

Then ASP.NET check _PageStart exists. If _PageStart exists, run the page before other requested pages _PageStart.

You _PageStart Page() in the page to specify where the requested page is running. Otherwise, by default, the requested page _PageStart run after the page runs.

That's ASP.NET about the Web Pages global page: AppStart and PageStart.