diff --git "a/28\345\256\213\345\256\210\344\270\200/0526-\347\254\254\344\272\224\347\253\240\344\275\234\344\270\232.md" "b/28\345\256\213\345\256\210\344\270\200/0526-\347\254\254\344\272\224\347\253\240\344\275\234\344\270\232.md" new file mode 100644 index 0000000000000000000000000000000000000000..d1ebe0715bd494cb88d454228d776da4eaf22612 --- /dev/null +++ "b/28\345\256\213\345\256\210\344\270\200/0526-\347\254\254\344\272\224\347\253\240\344\275\234\344\270\232.md" @@ -0,0 +1,255 @@ +#### 1 + + + +```C# +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using System.Web.Security; +using System.Web.SessionState; + +namespace WebApplication1 +{ + public class Global : System.Web.HttpApplication + { + + protected void Application_Start(object sender, EventArgs e) + { + Application.Lock(); + Application["visitor"] = 0; + Application["online"] = 0; + Application.UnLock(); + } + + protected void Session_Start(object sender, EventArgs e) + { + Application.Lock(); + Application["visitor"] = (int)Application["visitor"] + 1; + Application["online"] = (int)Application["online"] + 1; + Application.UnLock(); + } + + protected void Application_BeginRequest(object sender, EventArgs e) + { + + } + + protected void Application_AuthenticateRequest(object sender, EventArgs e) + { + + } + + protected void Application_Error(object sender, EventArgs e) + { + + } + + protected void Session_End(object sender, EventArgs e) + { + Application.Lock(); + Application["online"] = (int)Application["online"] - 1; + Application.UnLock(); + } + + protected void Application_End(object sender, EventArgs e) + { + + } + } + +} +``` + + + +```c# +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using System.Web.UI; +using System.Web.UI.WebControls; + +namespace WebApplication1 +{ + public partial class WebForm1 : System.Web.UI.Page + { + protected void Page_Load(object sender, EventArgs e) + { + Response.Write($"该网站的总访问人数{Application["visitor"]},当前在线人数{Application["online"]}"); + } + } +} +``` + + + +#### 2 + + + +```asp +<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %> + + + + + + + + + + + + +
+
+ + + + + + + + + + + + +
+ 用户名: + + + + +
+ 密码: + + + + +
+ + + +
+
+
+ + + +``` + + + +```c# +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using System.Web.UI; +using System.Web.UI.WebControls; + +namespace WebApplication1 +{ + public partial class WebForm1 : System.Web.UI.Page + { + protected void Page_Load(object sender, EventArgs e) + { + + + } + + protected void Button1_Click(object sender, EventArgs e) + { + string name = TextBox1.Text; + string pwd = TextBox2.Text; + if (name=="admin") + { + if (pwd == "123456") + { + Session["user"] = name; + Session["time"] = DateTime.Now; + Response.Redirect($"~/WebForm2.aspx?name={TextBox1.Text} &pwd={TextBox2.Text}"); + } + else + { + Response.Write(""); + } + } + else + { + Response.Write(""); + } + } + } + +} +``` + + + +```asp +<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="WebApplication1.WebForm2" %> + + + + + + + + + + + + +
+
+ +
+
+ + +``` + + + +```c# +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using System.Web.UI; +using System.Web.UI.WebControls; + +namespace WebApplication1 +{ + public partial class WebForm2 : System.Web.UI.Page + { + protected void Page_Load(object sender, EventArgs e) + { + if (Session["user"]!=null) + { + Response.Write($"欢迎用户" + Session["user"].ToString() + "登录本系统!
"); + Response.Write("您登录系统的时间:" + Session["time"].ToString()); + + } + else + { + Response.Redirect($"~/WebForm1.aspx"); + } + + } + + protected void Button1_Click(object sender, EventArgs e) + { + Session.Abandon(); + Response.Redirect($"~/WebForm1.aspx"); + } + } + +} +``` +