No 89 · 网络上实现单点登录

·
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using System.Web.Caching;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
            string str_Key = txtName.Text + "_" + txtPwd.Text;
            string str_User = Convert.ToString(Cache[str_Key]);
            if (str_User == String.Empty)
            {
                TimeSpan SessTimeOut = new TimeSpan(0, 0, HttpContext.Current.Session.Timeout, 0, 0); HttpContext.Current.Cache.Insert(str_Key, str_Key, null, DateTime.MaxValue, SessTimeOut, CacheItemPriority.NotRemovable, null);
                Session["User"] = str_Key;
                Response.Write("<h2 style='color:red'>你好,登录成功!");
            }
            else
            {
                Response.Write("<h2 style='color:red'>抱歉,您好像已经登录了!");
                return;
            }
    }
}

你可能感兴趣的:(No 89 · 网络上实现单点登录)