sso单点登录跳转异常 单点登录在ASP.NET上的简单实现[5]
单点登录在ASP.NET上的简单实现[5]
Shop的Synchronous cs 好了 我们在Service中完成了登录 并把用户状态传递回Shop站点 我们接着看用户状态是怎么同步的 首先 如果Session里的Security是空字符串 则表示Shop站点没有向Service发送过请求 而Service向Shop发回了请求 这显然是错误的 这次访问是由客户端伪造进行的访问 于是访问被拒绝了 同样Security和InSecurity不相同 则表示请求和应答是不匹配的 可能应答被纂改过了 所以应答同样被拒绝了 当检验Security通过后 我们保证Serive完成了应答 并且返回了确切的参数 下面就是读出参数同步Shop站点和Service站点的用户即时状态string InUserID = this Request QueryString[ UserID ];string InPass = this Request QueryString[ Pass ];string InSecurity = this Request QueryString[ Security ];string Security = this Session[ Security ] ToString();if (Security != ){ byte[] Value; UnicodeEncoding Code = new UnicodeEncoding(); byte[] Message = Code GetBytes(Security); SHA Managed Arithmetic = new SHA Managed(); Value = Arithmetic ComputeHash(Message); Security = ; foreach(byte o in Value) { Security += (int) o + O ; } if (Security == InSecurity) { if (InPass == True ) { this Session[ UserID ] = int Parse(InUserID); this Session[ Pass ] = true; this Response Redirect(this Session[ Url ] ToString()); } } else { this Response Write( ); this Response Write( ); this Response Write( ); this Response Write( ); this Response Write( ); this Response Write( ); this Response Write( ); this Response Write( 数据错误 ); this Response Write( ); this Response Write( ); this Response Write( ); }}else{ this Response Write( ); this Response Write( ); this Response Write( ); this Response Write( ); this Response Write( ); this Response Write( ); this Response Write( ); this Response Write( 访问错误 ); this Response Write( ); this Response Write( ); this Response Write( );}
Shop的Page cs 我们知道 页面在一段时间不刷新后 Session会超时失效 在我们一直访问Shop的时候怎么才能保证Service的Session不会失效呢?很简单 我们返回来看Shop的Page cs 通过在所有Shop的页面内都用<iframe>嵌套Service的某个页面 就能保证Service能和Shop的页面同时刷新 需要注意的一点是Service的Session必须保证不小于所有Shop和Office的Session超时时间 这个在Web config里可以进行配置
this Response Write( <iframe width= height= src= + project service + /Customer aspx ></iframe> );
![sso单点登录跳转异常 单点登录在ASP.NET上的简单实现[5]](http://img.zhputi.com/uploads/99e8/99e80c8bdd4e388d3cc09dfaf007dfac73548.jpg)
总结 一次完整的登录完成了 我们接着假设一下现在要跳到Office的Any页面 系统会进行怎样的操作呢?Any(用户没有登录) >Validate(用户已经登录) >Synchronous(同步) >Any 也就是说这次 用户没有进行登录的过程 我们通过一次登录 使得Service的用户状态为登录 并且不管有多少个网站应用 只要这些网站都保证符合Shop的特性 这些网站就都能保持Service的用户状态 同时能通过Service获得用户的状态 也就是说我们实现了SSO
lishixinzhi/Article/program/net/201311/14964