ASP.NET Tutoria...login
ASP.NET Tutorial
author:php.cn  update time:2022-04-11 14:18:18

Web Pages Global


ASP.NET Web Pages -Global Page


This chapter introduces global page 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.

_AppStart is typically used 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, for example: _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 to run before any page in each folder code.

For each folder in your website, you can add a file named _PageStart.

_PageStart Typical uses are to set a layout page for all pages in a folder, or to check if the user is logged in before running a page.


How does it work?

The following diagram shows how it works:

pic_webpages_pagestart.jpg

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.


php.cn