c#实现单点登陆

本文介绍了如何使用C#实现单点登录(SSO)系统。通过接收客户端传递的key值,系统向客户的ESB系统验证,验证成功后获取用户信息并与本地服务器用户信息对比。在客户内网环境且域名受限的情况下,需进行远程调试,并利用SOAP协议生成WSDL文件的代理类完成接口调用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

原理:客户访问我的超链接,传来一个key值,我通过这个key‘值去客户的esb系统去验证,若验证成功,返回用户信息,我拿到用户信息,跟本地服务器的用户信息进行比对,若一致,跳过登陆页面,直接授权进入系统。客户是内网,域名又有限制,访问不到接口,只能进行远程调试;因为获取用户用的是soap协议,所以还需要生成wsdl文件的代理类。

主要代码如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Security.Cryptography;
using TechExcel.Project.DataAccess;
using TechExcel.Project.DataAccess.Service;
using TechExcel.Project.DataAccess.Utility;
using System.Net;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.IO;
using System.Xml;
using TechExcel.PPM.ProjectWeb.WebServiceEastHope;

namespace TechExcel.PPM.ProjectWeb
{
    public partial class SSOLogin4EastHope : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            CookieContainer cookieContainer = new CookieContainer();
            string url = ConfigurationManager.AppSettings.Get("EastHopeEsbUrl");//esb接口的url
            string strUser= string.Empty;//用户信息
            string token = string.Empty;//key值
            string iPlanetDirectoryProVal = string.Empty;//
            int timeout = 0;
            string userAgent = string.Empty;
            string strLang = string.Empty;
            int nLangID = 0;
            int.TryParse(strLang, out nLangID);
            string strRuntimeKey = string.Empty;         
            if (Request.Cookies == null)
            {
                Response.Write("cookie is null");
                //Response.Redirect("login.aspx");
                return;
            }
            if (HttpContext.Current.Request.Cookies["tokenID"] != null)
            {
                iPlanetDirectoryProVal = HttpContext.Current.Request.Cookies["tokenID"].Value;
            }
            if (HttpContext.Current.Request.Cookies["iPlanetDirectoryPro"] != null)
            {
              
                string tokenTemp = HttpContext.Current.Request.Cookies["iPlanetDirectoryPro"].Value;
                Response.Write("iPlanetDirectoryPro is not null " + tokenTemp);
                string xmlToken=GetXml(tokenTemp);
                //拿到cookies的key值并且生成xml数据的格式之后,到ESB系统获取用户信息
                //Cookie cookie = new Cookie("tokenID", tokenTemp);
                //HttpHelper httpR = new HttpHelper();
                //HttpWebResponse re = httpR.CreateGetHttpResponse(url, timeout, userAgent, cookie,xmlToken);
                AuthenticationWSClient authticayion=new AuthenticationWSClient();
                string xmlIn=authticayion.getTokenUser(xmlToken);
                if (xmlIn != null)
                {
                    //string xmlIn = new StreamReader(re.GetResponseStream(), Encoding.UTF8).ReadToEnd();
                    strUser = getXmlUser(xmlIn);
                    Response.Write("xmlIn is not null " + xmlToken +  "  xmlIn:"+xmlIn+" strUser:"+strUser);
                    if (strUser != null)
                    {
                        if (SSOAuthentication(nLangID, strRuntimeKey, strUser))
                            return;
                    }
                }
                else
  &nb
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值