编程语言
首页 > 编程语言> > ASP.NET中简单实现单点登陆

ASP.NET中简单实现单点登陆

作者:互联网

原文链接:http://www.cnblogs.com/lx0831/archive/2009/04/02/1428415.html ContractedBlock.gifExpandedBlockStart.gifCode
ContractedBlock.gifExpandedBlockStart.gif单点登录#region 单点登录
ContractedSubBlock.gifExpandedSubBlockStart.gif        获取当前操作机器的MAC地址#region 获取当前操作机器的MAC地址
        [DllImport("Iphlpapi.dll")]
        private static extern int SendARP(Int32 dest, Int32 host, ref Int64 mac, ref Int32 length);
        [DllImport("Ws2_32.dll")]
        private static extern Int32 inet_addr(string ip);

        public static string sortMAC(string userip)
ExpandedSubBlockStart.gifContractedSubBlock.gif        {
            //string userip = Request.UserHostAddress;
            Int32 ldest = inet_addr(userip); //目的地的ip 
            Int32 lhost = inet_addr(""); //本地服务器的ip 
            Int64 macinfo = new Int64();
            Int32 len = 6;
            int res = SendARP(ldest, 0, ref macinfo, ref len);
            string mac_src = macinfo.ToString("X");

            while (mac_src.Length < 12)
ExpandedSubBlockStart.gifContractedSubBlock.gif            {
                mac_src = mac_src.Insert(0, "0");
            }

            string mac_dest = string.Empty;
            for (int i = 0; i < 11; i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif            {
                if (0 == (i % 2))
                    mac_dest = mac_dest.Insert(0, mac_src.Substring(i, 2));
            }
            return mac_dest;
        }
        #endregion

ContractedSubBlock.gifExpandedSubBlockStart.gif        获取数据库中MAC地址#region 获取数据库中MAC地址
        public static string GetMAC(string loginid)
ExpandedSubBlockStart.gifContractedSubBlock.gif        {
            Dictionary<string, object> dict = new Dictionary<string, object>();
            dict.Add("@LOGINID", loginid);
            UserOperationFacade facade = new UserOperationFacade();
            DataSet ds = facade.getUserIP(dict);
            return ds.Tables[0].Rows[0][0].ToString();
        }
        #endregion

ContractedSubBlock.gifExpandedSubBlockStart.gif        单点登录#region 单点登录
        public static bool ValidateMAC(string loginid,string userip)
ExpandedSubBlockStart.gifContractedSubBlock.gif        {
            bool back = true;
            if (sortMAC(userip) != GetMAC(loginid))
ExpandedSubBlockStart.gifContractedSubBlock.gif            {
                LogUtility.Write_SSOLog(userip, GetMAC(loginid), DateTime.Now, loginid);
                back = false;
                //HttpContext.Current.Response.Redirect("~/Login.aspx");              
            }
            return back;
        }
        #endregion
        #endregion

 

获得客户端本地的MAC地址。

但是这个方法只能用在局域网内,如果网站放在广域网上的话,是无法获得客户端的MAC地址的。

转载于:https://www.cnblogs.com/lx0831/archive/2009/04/02/1428415.html

标签:Int32,ASP,单点,string,MAC,mac,userip,NET,loginid
来源: https://blog.csdn.net/weixin_30302609/article/details/97386706