.net 单点登录的设计与实践(2)

/// <summary> /// 授权登陆验证 /// </summary> /// <returns></returns> [HttpPost] public ActionResult PassportVertify() { var cookie=Request.Cookies[ConstantHelper.USER_COOKIE_KEY]; if (cookie == null ||string.IsNullOrEmpty(cookie.ToString())) { return RedirectToAction("Login", new { ReturnUrl = Request["ReturnUrl"] ,Token= Request["Token"] }); } string userinfo = cookie.ToString(); var success= passportservice.AuthernVertify(Request["Token"], Convert.ToDateTime(Request["TimeStamp"])); if (!success) { return RedirectToAction("Login", new { ReturnUrl = Request["ReturnUrl"], Token = Request["Token"] }); } return Redirect(passportservice.GetReturnUrl(userinfo, Request["Token"],Request["ReturnUrl"])); }

已登陆则验证Token

/// <summary> /// 验证令牌 /// </summary> /// <param>令牌</param> /// <param>时间戳</param> /// <returns></returns> public bool AuthernVertify(string token,DateTime timestamp) { return AuthernUtil.CreateToken(timestamp) == token; }

测试说明

1、修改host

127.0.0.1

127.0.0.1

127.0.0.1

2、部署IIS

P :801

A :802

B :803

3、测试账号和webconfig

<add key="PassportCenterUrl" value="http://www.passport.com:801"/>

用户名:admin  密码:123

demo

下载地址:源码下载地址

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wjygyy.html