<%@ Import Namespace="System.IO"%> <%@ Application Language="C#" %> <script runat="server"> void Application_Start(Object sender, EventArgs e) { // Code that runs on application startup Application["OnlineNow"] = 0; } void Application_End(Object sender, EventArgs e) { // Code that runs on application shutdown Application["OnlineNow"] = null; } void Application_Error(Object sender, EventArgs e) { // Code that runs when an unhandled error occurs StreamWriter StrWer; StrWer = new StreamWriter(Server.MapPath("log/").ToString() + "thaicreate.txt", true); StrWer.WriteLine(DateTime.Now.ToString() + " - The Application Error"); StrWer.Close(); } void Session_Start(Object sender, EventArgs e) { // Code that runs when a new session is started Application.Lock(); Application["OnlineNow"] = (int)Application["OnlineNow"] + 1; Application.UnLock(); } void Session_End(Object sender, EventArgs e) { Application.Lock(); Application["OnlineNow"] = (int)Application["OnlineNow"] - 1; Application.UnLock(); } </script>
<%@ Page Language="VB" %> <script runat="server"> Sub Page_Load(sender As Object, e As EventArgs) Me.lblText.Text = Application("OnlineNow") & " Online" End Sub </script> <html> <head> <title>ThaiCreate.Com ASP.NET - Global.asax</title> </head> <body> <form id="form1" runat="server"> <asp:Label id="lblText" runat="server"></asp:Label><br /> </form> </body> </html>
ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท