Share the ASP. NET Learning Notes (5) global page AppStart and Pagestart

Source: Internet
Author: User
This chapter describes global pages AppStart and Pagestart.

Before the Web starts: _appstart

Most of the server-side code is written on the personal page. For example, if the 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 named _appstart under your site's root directory. If this page is present, ASP. NET will run this page first when other pages in the site are requested.

The typical use of _appstart is to start code and initialize global values (such as counters and global names).

Note 1:_appstart has the same file name extension as your Web page, such as: _appstart.cshtml.

Note The 2:_appstart has an underscore prefix. Therefore, these files cannot be browsed directly.

Before each page: _pagestart

Just as _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 named _pagestart.

How does it work?

Shows how it works:

When a request is received, ASP. NET first checks to see if the _appstart exists. If _appstart exists and this is the first request received by the site, run _appstart.

Then ASP. NET checks if the _pagestart exists. If _pagestart exists, run _pagestart before the other requested page runs.

You can call Runpage () in _pagestart to specify where the requested page will run. Otherwise, by default, the requested page is run after _pagestart is run.

"Recommended"

1. ASP. NET free Video Tutorials

2. Share the ASP. NET Learning Notes (1)--webpages Razor

3. Share the ASP. NET Learning Notes (2)--webpages Introduction

4. Share the ASP. NET Learning Notes (3) Webpages layout

5. Share the ASP. NET Learning Notes (4) folder

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.