轻量级单点登录系统最佳实践(十)——5.5. 财务管理系统演示SSOLab. APP2. 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=app2"> </script>形式Get单点登录系统上下文信息,自动绑定到Form相应字段并自动提交到后台。
l SSOController.aspx.cs财务管理系统单点登录控制页后台代码。接受前台提交的信息,对用户信息进行解密,判定当前用户是否登录。如果已登录返回系统首页,如果没有登录,跳转到单点登录系统登录页。
Default.aspx
Code
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="SSOLab.App2.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.App2.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.App2.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.App2.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.App2.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=app2">
</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.App2.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=app2">
</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.Xml;
using SSOLab.SSOServer.Components;
using System.Web.Security;
namespace SSOLab.App2.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 = "XBtyndN8yHpZCiM1eO9XtE1qii9Oey17CYosH8cM7nRnXBIBjdN811pZrtw1PfhcBDyq7S9OeHcGmWAR7ycM7aloXBCsXQhe10FgrBEwPfSndDZpGwxbL55ymWAmhycM";
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.Xml;
using SSOLab.SSOServer.Components;
using System.Web.Security;
namespace SSOLab.App2.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 = "XBtyndN8yHpZCiM1eO9XtE1qii9Oey17CYosH8cM7nRnXBIBjdN811pZrtw1PfhcBDyq7S9OeHcGmWAR7ycM7aloXBCsXQhe10FgrBEwPfSndDZpGwxbL55ymWAmhycM";
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 21:11 guushuuse 阅读(1025) 评论(2) 编辑 收藏 举报