l Default.aspx企业门户系统首页。显示当前用户信息和应用系统链接。
l Default.aspx.cs企业门户系统首页后台代码。
l SSOController.aspxs企业门户系统单点登录控制页。使用<script type="text/javascript" src="http://localhost:7771/SSOSite/SSOContext.aspx?app=portal"> </script>形式Get单点登录系统上下文信息,自动绑定到Form相应字段并自动提交到后台。
l SSOController.aspx.cs企业门户系统单点登录控制页后台代码。接受前台提交的信息,对用户信息进行解密,判定当前用户是否登录。如果已登录返回系统首页,如果没有登录,跳转到单点登录系统登录页。
Default.aspx
Code
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="SSOLab.Portal.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>
<h1>
业务系统</h1>
<div>
<a href="http://localhost:7773/App1/Default.aspx" target="_blank">人力资源管理系统</a></div>
<div>
<a href="http://localhost:7774/App2/Default.aspx" target="_blank">财务管理系统</a></div>
<div>
<a href="http://localhost:8080/App3/default.jsp" target="_blank">网上办公系统</a></div>
</div>
</div>
</form>
</body>
</html>
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="SSOLab.Portal.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>
<h1>
业务系统</h1>
<div>
<a href="http://localhost:7773/App1/Default.aspx" target="_blank">人力资源管理系统</a></div>
<div>
<a href="http://localhost:7774/App2/Default.aspx" target="_blank">财务管理系统</a></div>
<div>
<a href="http://localhost:8080/App3/default.jsp" target="_blank">网上办公系统</a></div>
</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.Portal.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.Portal.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.Portal.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=portal">
</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.Portal.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=portal">
</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 System.Web.Security;
using SSOLab.SSOServer.Components;
using System.Xml;
namespace SSOLab.Portal.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 = "Xj1wD4DT7UicRVxOBJdjAg2AjErHkoEDlB9GqMJtYMwbfbnc9slagStcVt0Y3lY0XVKDnn6nO9cnCPDwM0tJU6iCBlWEoomDfjAjhobLurOxHR8ua8a25NGNQXQ1Q34X";
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 System.Web.Security;
using SSOLab.SSOServer.Components;
using System.Xml;
namespace SSOLab.Portal.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 = "Xj1wD4DT7UicRVxOBJdjAg2AjErHkoEDlB9GqMJtYMwbfbnc9slagStcVt0Y3lY0XVKDnn6nO9cnCPDwM0tJU6iCBlWEoomDfjAjhobLurOxHR8ua8a25NGNQXQ1Q34X";
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);
}
}
}
}
}