单点登录SSO http://www.open-open.com/lib/view/open1394852821353.html
以前做类似的需求用的是cookie
将sessionid的cookie作用域改为".域名.com"原来的应该是"www.域名.com"
最简单的,登录成功后,给响应添加两个 cookie,一个一级域名,另一个二级域名。
session共享,比如独立缓存服务器,缓存session
用js结合iframe传cookie过去
用session的替代方案memcache吧。就专门用台服务器作数据缓存
好像用session不稳定,并且传到服务器上后,就没有本地的效果了,建议用cookie,但是最好别存汉语
public class SessionSharedHttpModule : IHttpModule { string _rootDomain = null; public void Dispose() { } public void Init(HttpApplication context) { _rootDomain = ".yiji.com"; Type stateServerSessionProvider = typeof(HttpSessionState).Assembly.GetType("System.Web.SessionState.OutOfProcSessionStateStore"); FieldInfo uriField = stateServerSessionProvider.GetField("s_uribase", BindingFlags.Static | BindingFlags.NonPublic); if (uriField == null) throw new ArgumentException("UriField was not found"); uriField.SetValue(null, _rootDomain); context.EndRequest += new EventHandler(context_EndRequest); } /// <summary> /// 从发送给客户端的Cookie集合中找出记录会话ID的Cookie /// 并修改它的Domain属性值为要共享的一级域名 /// </summary> void context_EndRequest(object sender, System.EventArgs e) { HttpApplication app = sender as HttpApplication; for (int i = app.Context.Response.Cookies.Count - 1; i >= 0; i--) { //ASP.NET_SessionId是默认的存储会话ID的key,如果修改了默认值这里要修改成一致的 if (app.Context.Response.Cookies[i].Name.Equals("ASP.NET_SessionId")) { app.Context.Response.Cookies[i].Domain = _rootDomain; return; } } } }
配置文件中加入
<httpModules> <add name="MakeSessionIDOneOnly" type="MakeSessionIDOneOnly.SessionSharedHttpModule, MakeSessionIDOneOnly" /> </httpModules>
mark