轻量级单点登录系统最佳实践(九)——5.4. 人力资源管理系统演示SSOLab. APP1. WebApp
Default.aspx人力资源管理系统首页。显示当前用户信息。
Default.aspx.cs人力资源管理系统首页后台代码。
SSOController.aspxs人力资源管理系统单点登录控制页。使用形式Get单点登录系统上下文信息,自动绑定到Form相应字段并自动提交到后台。
SSOController.aspx.cs人力资源管理系统单点登录控制页后台代码。接受前台提交的信息,对用户信息进行解密,判定当前用户是否登录。如果已登录返回系统首页,如果没有登录,跳转到单点登录系统登录页。
l Default.aspx人力资源管理系统首页。显示当前用户信息。
l Default.aspx.cs人力资源管理系统首页后台代码。
l SSOController.aspxs人力资源管理系统单点登录控制页。使用<script type="text/javascript" src="http://localhost:7771/SSOSite/SSOContext.aspx?app=app1"> </script>形式Get单点登录系统上下文信息,自动绑定到Form相应字段并自动提交到后台。
l SSOController.aspx.cs人力资源管理系统单点登录控制页后台代码。接受前台提交的信息,对用户信息进行解密,判定当前用户是否登录。如果已登录返回系统首页,如果没有登录,跳转到单点登录系统登录页。
Default.aspx
Code
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="SSOLab.App1.WebApp._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>人力资源管理系统</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h1>
人力资源管理系统</h1>
<div>
当前登录用户:<asp:Label ID="lblUserID" runat="server" />
</div>
</div>
</form>
</body>
</html>
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="SSOLab.App1.WebApp._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>人力资源管理系统</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h1>
人力资源管理系统</h1>
<div>
当前登录用户:<asp:Label ID="lblUserID" runat="server" />
</div>
</div>
</form>
</body>
</html>
Default.aspx.cs
Code
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace SSOLab.App1.WebApp
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
lblUserID.Text = HttpContext.Current.User.Identity.Name;
}
}
}
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace SSOLab.App1.WebApp
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
lblUserID.Text = HttpContext.Current.User.Identity.Name;
}
}
}
SSOController.aspx
Code
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SSOController.aspx.cs"
Inherits="SSOLab.App1.WebApp.SSOController" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div style="visibility: hidden">
<asp:TextBox ID="sso_signinurl" runat="server" />
<asp:TextBox ID="sso_signouturl" runat="server" />
<asp:TextBox ID="sso_userinfo" runat="server" />
<asp:TextBox ID="isSubmit" runat="server" Text="0" />
<asp:Button ID="btnSubmit" runat="server" Text="自动提交" />
</div>
</form>
<script type="text/javascript" src="http://localhost:7771/SSOSite/SSOContext.aspx?app=app1">
</script>
<script type="text/javascript">
if (document.getElementById("isSubmit").value != "1") {
document.getElementById("sso_signinurl").value = ssoContext.signInUrl;
document.getElementById("sso_signouturl").value = ssoContext.signOutUrl;
document.getElementById("sso_userinfo").value = ssoContext.userInfo;
document.getElementById("isSubmit").value = "1";
document.getElementById("form1").submit();
}
</script>
</body>
</html>
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SSOController.aspx.cs"
Inherits="SSOLab.App1.WebApp.SSOController" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div style="visibility: hidden">
<asp:TextBox ID="sso_signinurl" runat="server" />
<asp:TextBox ID="sso_signouturl" runat="server" />
<asp:TextBox ID="sso_userinfo" runat="server" />
<asp:TextBox ID="isSubmit" runat="server" Text="0" />
<asp:Button ID="btnSubmit" runat="server" Text="自动提交" />
</div>
</form>
<script type="text/javascript" src="http://localhost:7771/SSOSite/SSOContext.aspx?app=app1">
</script>
<script type="text/javascript">
if (document.getElementById("isSubmit").value != "1") {
document.getElementById("sso_signinurl").value = ssoContext.signInUrl;
document.getElementById("sso_signouturl").value = ssoContext.signOutUrl;
document.getElementById("sso_userinfo").value = ssoContext.userInfo;
document.getElementById("isSubmit").value = "1";
document.getElementById("form1").submit();
}
</script>
</body>
</html>
SSOController.aspx.cs
Code
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SSOLab.SSOServer.Components;
using System.Xml;
using System.Web.Security;
namespace SSOLab.App1.WebApp
{
public partial class SSOController : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!String.IsNullOrEmpty(Request.Params["isSubmit"]) && Request.Params["isSubmit"] == "1")
{
try
{
string ssoKey = "XD0cEmXD0IcmYD0gBmYE0OdnYE1jHnZE1USnZF3y3GYpm93Gjp2s2GSog32FfoDm2FZoaG2FZnmhpkVBlJXkWB1eGkWCqA2lWC7k2lXCw1dlXDMqolZr805InrQk4Ixq";
string userInfo = SSOUtil.DESDecrypt(Request.Params["sso_userinfo"], ssoKey.Substring(ssoKey.Length / 2 - 1, 8));
Response.Write(userInfo);
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(userInfo);
if (xmlDoc.SelectSingleNode("/userinfo/islongin").InnerText == "true")
{
FormsAuthentication.RedirectFromLoginPage(xmlDoc.SelectSingleNode("/userinfo/username").InnerText, false);
}
else
{
string returnUrl = SSOUtil.GetHostUrl() + FormsAuthentication.LoginUrl;
Response.Redirect(Request.Params["sso_signinurl"] + "?ReturnUrl=" + HttpUtility.UrlEncode(returnUrl));
}
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
}
}
}
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SSOLab.SSOServer.Components;
using System.Xml;
using System.Web.Security;
namespace SSOLab.App1.WebApp
{
public partial class SSOController : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!String.IsNullOrEmpty(Request.Params["isSubmit"]) && Request.Params["isSubmit"] == "1")
{
try
{
string ssoKey = "XD0cEmXD0IcmYD0gBmYE0OdnYE1jHnZE1USnZF3y3GYpm93Gjp2s2GSog32FfoDm2FZoaG2FZnmhpkVBlJXkWB1eGkWCqA2lWC7k2lXCw1dlXDMqolZr805InrQk4Ixq";
string userInfo = SSOUtil.DESDecrypt(Request.Params["sso_userinfo"], ssoKey.Substring(ssoKey.Length / 2 - 1, 8));
Response.Write(userInfo);
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(userInfo);
if (xmlDoc.SelectSingleNode("/userinfo/islongin").InnerText == "true")
{
FormsAuthentication.RedirectFromLoginPage(xmlDoc.SelectSingleNode("/userinfo/username").InnerText, false);
}
else
{
string returnUrl = SSOUtil.GetHostUrl() + FormsAuthentication.LoginUrl;
Response.Redirect(Request.Params["sso_signinurl"] + "?ReturnUrl=" + HttpUtility.UrlEncode(returnUrl));
}
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
}
}
}
posted on 2009-05-04 20:09 guushuuse 阅读(1250) 评论(1) 编辑 收藏 举报