首页 > 代码库 > Asp.Net_单点登录
Asp.Net_单点登录
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, EventArgs e) { if (Application["UsName"] != null) { Response.Write("记录的用户名:" + Application["UsName"]); } } /// <summary> /// 登录 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void OnloginbtnClick(object sender, EventArgs e) { if (txt_UsName.Text.Length > 0 && txt_UsPwd.Text.Length > 0) { if (Application["UsName"] != null) { //判断用户是否已经登录过 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(‘你已经登录!‘);</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(‘成功登录!‘);</script>"); } else { Response.Write("<script>alert(‘请填写用户名和密码!‘);</script>"); } } /// <summary> /// 退出登录 /// </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"] + "已经成功退出" + "!‘);</script>"); } } }
void Application_Start(object sender, EventArgs e)
{ //在应用程序启动时运行的代码 Application["UsName"] = null; }
Asp.Net_单点登录
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。