A站点用单点登录后,B站点就不用认证(并且通过认证把用户信息保存在session中),当A站点退出,如何将B站点的Session过期同时可以退出B站点? 如A站没有登录,B站用自己普通的登录界面也能进入不受A站的单点控制?
页面代码判断如下:
SessionUser user = (SessionUser)Session["SESSION_USER"];
if (user == null)
CASLoginHelper.GetSingle().LoginByCAS(HttpContext.Current);
验证代码处理如下:
public void LoginByCAS(HttpContext context)
{
//到配置文件中 获取cas的地址
string casHost = ConfigurationManager.AppSettings["casUrl"].ToString();
// 获取url是否有ticket
string ticket = context.Request.QueryString["ticket"];
// 获取客户端url
string service = context.Request.Url.GetLeftPart(UriPartial.Query);
if (service.Contains("ticket"))
service = service.Substring(0, service.LastIndexOf("ticket") - 1);
// 第一次登录 ticket 为空 跳到cas服务器登录
string redir = string.Empty;
if (ticket == null || ticket.Length == 0)
{
context.Session.Abandon(); //取消当前会话
context.Session.Clear(); //清除当前浏览器所以Session
redir = casHost + "login?" + "service=" + service;
context.Response.Redirect(redir);
return;
}
// 第二次 验证ticket
string netid = ValidateTicket(casHost, ticket, service);
//判断 netid
if (netid == null)
{
redir = casHost + "login?" + "service=" + service;
context.Response.Redirect(service);
return;
}
else
{
if (WriteUserSession(netid, context))
{
context.Response.Redirect(service);
return;
}
else
{
context.Response.Write("抱歉,请联系管理员开启 BI 帐户!!!");
context.Response.End();
}
}
}
private string ValidateTicket(string casHost, string ticket, string service)
{
string validateurl = casHost + "serviceValidate?" + "ticket=" + ticket + "&" + "service=" + service;
//ServicePointManager.ServerCertificateValidationCallback = ValidateServerCertificate;
StreamReader Reader = new StreamReader(new WebClient().OpenRead(validateurl));
string resp = Reader.ReadToEnd();
NameTable nt = new NameTable();
XmlNamespaceManager nsmgr = new XmlNamespaceManager(nt);
XmlParserContext context = new XmlParserContext(null, nsmgr, null, XmlSpace.None);
XmlTextReader reader = new XmlTextReader(resp, XmlNodeType.Element, context);
string netid = null;
while (reader.Read())
{
if (reader.IsStartElement())
{
string tag = reader.LocalName;
string jobnumber = reader.ReadString();
if (tag == "jobnumber")
{
netid = jobnumber;
break;
}
}
}
return netid;
}
目前这种方式可以实现单点登录后获取值,但是退出单点登录,B站还是保留Session,如不关闭浏览器,Session一直存在无法退出)
需要消息推送机制
不是很清楚,请问如何实现