Asp.Net_单点登录
2016-12-19 11:32
260 查看
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跨应用程序进行登录的解决 (摘)
- ASP.NET跨应用程序进行登录的解决
- 用C#(asp.net)写出登录验证码!
- 在ASP.NET 中实现单点登录
- 在ASP.NET 中实现单点登录
- 利用asp.net制作登录页面
- asp.net做WEB登录
- ASP.NET 安全认证(三)——用Form 表单认证实现单点登录(Single Sign On) 作者:寒羽枫
- 在ASP.NET 中实现单点登录(从老孟那里抄的)
- 在ASP.NET中使用WINDOWS模式登录SQL数据库
- ASP.NET仅配置数据库MSDE出现"用户 ’机器名/ASPNET’ 登录失败 解决方法
- ASP.NET跨应用程序进行登录的解决
- 编写asp.net登录界面时,在不会使用cookie的情况下,暂时解决方法.
- 在ASP.NET中怎么用SESSION判断用户是否登录?(原创)
- 在ASP.NET 中实现单点登录
- 问题:asp.net如何防止用户用同一账号重复登录
- 在ASP.NET 中实现单点登录
- VB.Net + asp.net的一个web系统,使用SQL2000数据库 现在运行时偶尔会出现一个奇怪现象,一个用户登录时,登录后的界面竟然是另一个用户
- ASP.NET 安全认证(四)——巧妙实现 Form 表单认证跨站点、跨服务器的单点登录(Single Sign On) 作者:寒羽枫
- 单点登录在ASP.NET上的简单实现