ASP. NET Web Pages-Global Pages, asp. netpages

Source: Internet
Author: User

ASP. NET Web Pages-Global Pages, asp. netpages
Before starting the Web: _ AppStart

Most server-side code is written on an independent webpage. For example, if a webpage contains an input form, the webpage usually contains the server code used to read data.

However, by creating a page named _ AppStart in the root directory of the site, you can run the startup code before the site starts ). If the page exists, ASP. NET runs the page before any page in the site is requested.

Usually _ AppStart is used to initialize code and global values, such as counters and global names.

NOTE 1: The file extension of _ AppStart should be the same as that of the webpage, for example, _ AppStart. cshtml.

NOTE 2: _ AppStart has an underline prefix. Therefore, you cannot directly view the file.



Before each page: _ PageStart

Just like running _ AppStart before the site starts, you can run code before any page in each folder.

For each folder on the web, you can add a file named _ PageStart.

Usually _ PageStart is used to set layout files for all pages in the folder, or to check user logon before running the page.



How to work?

The following shows how it works:

When the request arrives, ASP. NET checks whether _ AppStart exists. If it exists and is the first request to the site, run _ AppStart.

Then ASP. NET checks whether _ PageStart exists. If yes, run _ PageStart before the requested page.

If you reference a call to RunPage () in _ PageStart, you can specify where to run the requested page. Otherwise, _ PageStart runs before the requested page.

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.