Home >Backend Development >C#.Net Tutorial >Share ASP.NET study notes (5) Global page AppStart and PageStart

Share ASP.NET study notes (5) Global page AppStart and PageStart

零下一度
零下一度Original
2017-05-25 09:09:473546browse

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:

Share ASP.NET study notes (5) Global page AppStart and PageStart

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn