6、CRM2011编程实战——单点登录

需求:在我们的CRM2011系统中,要跳转到新的系统中,可是又不想再次输入密码,这个时候,我们就应该考虑使用单点登录了。

解决方案:这里,由于系统安全性要求不是很高,所以是先将帐号和密码加密后,直接传送给新系统,当新系统接收到帐号和密码后解密自动登录。

新建一个html页面作为中转页面Skip.htmhxcs_Huaxu.RESTAPI.js是自定义的一个helper js类库代码。如下:

<!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>
    <title></title>
     <script language="javascript" src="/WebResources/hxcs_Huaxu.RESTAPI.js"></script>
</head>
<body>
<script type="text/javascript">
    OpenHtml();
    function OpenHtml() {
        var userId = "";
        userId = parent.Xrm.Page.context.getUserId();
        var queryString = "$select=DomainName&$filter=SystemUserId eq guid'" + userId + "'";
        var results = Huaxu.RESTAPI.retrieveMultipleRecordsSynchro("SystemUser", queryString);
        var userName = "";
        if (results.exception != null) {
            alert("获取用户名失败\n" + results.exception.description);
            return;
        }
        else {
            var _domainName = results.result[0].DomainName;
            userName = _domainName.substring(_domainName.indexOf("\\") + 1, _domainName.length);
        }

        window.location.href = "/ISV/Skip.aspx?userid=" + userName;
        window.opener = null;
        window.open("", "_self");
        window.close();
    }
</script>
</body>
</html>

新建一个aspx页面Skip.aspx,代码如下:

<%@ Page Language="C#" AutoEventWireup="true" Inherits="Skip" Codebehind="Skip.aspx.cs" %>

<!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>
    <script type="text/javascript">
        function showAll(url) {
            window.open(url, "", "channelmode,scrollbars")
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
    </div>
    </form>
</body>
</html>

后台代码如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;

namespace IsWaterWeb
{
    public partial class Skip : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string userid = Request.QueryString["userid"];
            if (string.IsNullOrEmpty(userid))
                return;
            byte[] bytes = Encoding.Default.GetBytes(userid);
            string encryptUserId = Convert.ToBase64String(bytes);
            //http://172.16.200.226:8080/koyoo/LoginByOther.action?Name=Y2NhZG1pbg==&Pwd=Y2NhZG1pbg==
            string url = string.Format("http://172.16.200.226:8080/koyoo/LoginByOther.action?Name={0}&Pwd=MDAwMDAw", encryptUserId);
            //Response.Redirect(url);
            ClientScript.RegisterStartupScript(this.GetType(), "show", "<script>showAll('" + url + "')</script>");
        }
    }
}




  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

邹琼俊

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值