Brief Introduction to Application and counter instances

Source: Internet
Author: User

Brief Introduction to application and counter instances

Event-handling method description
  
Application_start () occurs when the application starts
This is the first time that he has received a request from any user.
  
Application_end () occurs when the application is closed, usually because the network server is restarting.
  
In application_beginrequest (), the Code on this page is executed when the application of each request obtains the code.
  
Application_endrequest ()


Simple Storage value instance

<% @ Page language = "vb" %>

<Script runat = "server">
Sub page_load (sender as object, e as eventargs)
Lbloutput. text = "page loading "&_
"Application started at:" & application ("time") & "<br> "&_
"Current time:" & datetime. now & "<br>"
End sub

Sub click (obj as object, e as eventargs)
Session. abandon ()
End sub
</Script>

<Html> <body>
<Form runat = "server">
<Asp Tutorial: label id = "lbloutput" runat = "server"/>
<Asp: button id = "btsubmit" runat = "server" onclick = "click" text = "end this session"/>
</Form>
</Body>

Simple counters using application

<% @ Page language = "c #" %>
<! Doctype html public "-// w3c // dtd xhtml 1.0 transitional // en"
Http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd>
<Script runat = "server">
Void page_load ()
{
Lblsessioncount. text = application ["sessioncount"]. tostring ();
}
</Script>
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head id = "head1" runat = "server">
<Title> show session count </title>
</Head>
<Body>
<Form id = "form1" runat = "server">
<Div>
Total application sessions:
<Asp: label
Id = "lblsessioncount"
Runat = "server"/>

</Div>
</Form>
</Body>
</Html>

Lock application

<% @ Page language = "c #" autoeventwireup = "true" codefile = "default. aspx. cs" inherits = "_ default" %>

<! Doctype html public "-// w3c // dtd xhtml 1.0 transitional // en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">

<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> untitled page </title>
</Head>
<Body>
<Form id = "form1" runat = "server">
<Div>
The page has been requested
<Asp: label id = "mylabel" runat = "server"/>
Times!
</Div>
</Form>
</Body>
</Html>

File: default. aspx. cs

Using system;
Using system. data;
Using system. configuration;
Using system. web;
Using system. web. security;
Using system. web. ui;
Using system. web. ui. webcontrols;
Using system. web. ui. webcontrols. webparts;
Using system.web.ui.html controls;

Public partial class _ default: system. web. ui. page
{
Protected void page_load (object sender, eventargs e)
{
If (application ["pagecounter"]! = Null &&
(Int) application ["pagecounter"]> = 10)
{
Application. remove ("pagecounter ");
}

If (application ["pagecounter"] = null)
{
Application ["pagecounter"] = 1;
}
Else
{
Application. lock ();
Application ["pagecounter"] =
(Int) application ["pagecounter"] + 1;
Application. unlock ();
}
Mylabel. text = convert. tostring (application ["pagecounter"]);
}
}

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.