Asp. NET rookie Road of application small example

Source: Internet
Author: User

background
  • I am an ASP., temporarily began to learn ASP. NET, in this record I personally knock code, not much reference value, please see the pots of friends for me to support me a bit, thank you. Session Introduction
  • The Application object is used to hold information that is shared with all users, such as the number of web logins.
  • When modifying the Application object, lock unlock is required to prevent the simultaneous operation from causing the problem.
  • The life cycle of application object members ends when IIS is closed or cleared using the clear method.
  • Application Pass Value

  • describe the number of people who entered the site application records.
  • Create a new global variable file, Globle.asax, to write code in three events
  • voidApplication_Start (Objectsender, EventArgs e) {        //code to run when the application startsapplication["Cuscount"] =0; } voidSession_Start (Objectsender, EventArgs e) {        //code to run when a new session is startedApplication.Lock (); application["Cuscount"] =(int) application["Cuscount"] +1;    Application.UnLock (); }voidSession_End (Objectsender, EventArgs e) {        //The code that runs at the end of the session. //Note: Only the sessionstate mode in the Web. config file is set to//InProc, the Session_End event is not raised. If the session mode is set to StateServer//or SQL Server, the event is not raised. Application.Lock (); application["Cuscount"] = (int) application["Cuscount"] -1;    Application.UnLock (); }

    Then write a new Web form, write method

    protected void Page_Load (object  sender, EventArgs e)    {        Response.Write (" Welcome, section " + application["cuscount " " bit customer <br/> " );            }

    Let's introduce application. Retrieve data by index

    Use previous page, write method

  • protected voidPage_Load (Objectsender, EventArgs e) {Response.Write ("welcome you, the first"+ application["Cuscount"] +"Customers <br/>"); Application.add ("Key1","Value1"); Application.add ("Key1","Value1"); Application.add ("Key1","Value1");  for(intindex =0; Index < Application.count; index++) {Response.Write (Application.getkey (Index)+": "); Response.Write (Application.get (Index)+"<br/>"); }    }
  • This page shows

    Asp. NET rookie Road of application small example

    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.