Using system;using system.collections.generic;using system.linq;using system.web;using System.Web.UI;using System.web.ui.webcontrols;public partial class _default:system.web.ui.page{protected void Page_Load (object sender, E Ventargs e) {if (application["Usname"]! = null) {Response.Write ("Logged User name:" + application["UsN Ame "]); }}///<summary>//Login///</summary>//<param name= "sender" ></param>//&L T;param name= "E" ></param> protected void Onloginbtnclick (object sender, EventArgs e) {if (Txt_usnam E.text.length > 0 && txt_UsPwd.Text.Length > 0) {if (application["Usname"]! = NULL) {//Determine if the user has logged in string[] usnamearray=application["Usname"]. ToString (). Split (', '); for (int i = 0; i < usnamearray.length; i++) {if (usnamearray[i] = = Txt_usname.text. Trim ()) {Response.Write (' <script>alert (' You are already logged in! '); </script> "); Return }}} String strsplit = ""; session["loginusname"] = Txt_UsName.Text.Trim (); Application.Lock (); if (application["Usname"]! = null) {Strsplit = ","; } application["Usname"] = application["Usname"] + strsplit + session["Loginusname"]. ToString (); Application.UnLock (); Response.Write ("<script>alert (' successful login! '); </script> "); } else {Response.Write (' <script>alert (' please fill in user name and password! '); </script> "); }}///<summary>//Sign Out///</summary>//<param name= "sender" ></param>// <param name= "E" ></param> protected void Onsignoutbtnclick (object sender, EventarGS e) {if (session["Loginusname"]! = null) {Application.Lock (); application["usname"] = application["Usname"]. ToString (). Replace (session["Loginusname"]. ToString (), ""); Application.UnLock (); Response.Write ("<script>alert" + session["loginusname"] + "has successfully exited" + "!"); </script> "); } }}
void Application_Start (object sender, EventArgs e)
{ //code run at application startup application["usname"] = null; }
Asp.net_ Single Sign-on