轻量级单点登录系统最佳实践(九)——5.4. 人力资源管理系统演示SSOLab. APP1. WebApp...

 

Default.aspx人力资源管理系统首页。显示当前用户信息。

Default.aspx.cs人力资源管理系统首页后台代码。

SSOController.aspxs人力资源管理系统单点登录控制页。使用<script type="text/javascript" src="http://localhost:7771/SSOSite/SSOContext.aspx?app=app1"> </script>形式Get单点登录系统上下文信息,自动绑定到Form相应字段并自动提交到后台。

SSOController.aspx.cs人力资源管理系统单点登录控制页后台代码。接受前台提交的信息,对用户信息进行解密,判定当前用户是否登录。如果已登录返回系统首页,如果没有登录,跳转到单点登录系统登录页。

 

Default.aspx

 

ContractedBlock.gif ExpandedBlockStart.gif 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>

 

 

Default.aspx.cs

ContractedBlock.gif ExpandedBlockStart.gif 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;
        }
    }
}

 

 

SSOController.aspx

ContractedBlock.gif ExpandedBlockStart.gif 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>
 

SSOController.aspx.cs

ContractedBlock.gif ExpandedBlockStart.gif 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 - 18));
                    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);
                }
            }
        }


    }
}

 

转载于:https://www.cnblogs.com/guushuuse/archive/2009/05/04/1449032.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值