怎么解决呀?虚心请教!

解决方案 »

  1.   

    using System;
    using CBasic.Utility;
    using CBasic.ForumsWebService;
    using System.Net;
    using System.IO;
    using System.Text;
    using System.Xml;namespace CBasic.Web.UserControl
    {
        public partial class User_Login : CBasic.Web.UserControlBase
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                LoginButton.OnClientClick = "getElement('loginStat').style.display='';var u=getElement('" + UserName.ClientID + "');var p=getElement('" + UserPassword.ClientID + "');return checkLogin(u.value,p.value)";
            }        protected void Login_OnClick(object sender, EventArgs e)
            {
                if (!Validator.IsValidUserName(UserName.Text))
                    MessageBox.AlertMsg("用户名格式不正确", null);
                if (!Validator.IsValidPassword(UserPassword.Text))
                    MessageBox.AlertMsg("密码格式不正确", null);            string username = UserName.Text;
                string password = Text.MD5(UserPassword.Text, 16);            //Response.Write(Login(Config.Web.ForumsApiKeys, username, password));
                //Response.End();            BLL.Passport passport = new BLL.Passport();
                if (passport.MemberLogin(username, password) == null)
                    MessageBox.AlertMsg("您输入的用户不存在或密码错误", null);            //远程登录
                //MemberPassport ws = new MemberPassport();
                //string sysKey = Config.Web.ForumsApiKeys;
                //string r = ws.Login(sysKey, username, password);
                //Response.Write(r);
                //Response.Write("dv_dpo.asp?syskey=" + Text.MD5(username+sysKey, 16) + "&UserName=" + username + "&Password=" + password);//469e80d32c0559f8");
                //Response.End();
                //登录结束            Response.Redirect(FromUrl, true);
            }        private string Login(string sysKey, string userName, string password)
            {
                string param = "syskey=" + sysKey + "&UserName=" + userName + "&Password=" + password + "&savecookie=0";
                byte[] bs = Encoding.UTF8.GetBytes(param);
                //Response.ContentType = "text/xml";
                XmlDocument doc = new XmlDocument();
                string xmlPath = Server.MapPath("~/api_user.xml");
                doc.Load(xmlPath);            XmlNode root = doc.SelectSingleNode("/root");
                root.SelectSingleNode("action").InnerText = "login";
                root.SelectSingleNode("syskey").InnerText = sysKey;
                root.SelectSingleNode("username").InnerText = userName;
                root.SelectSingleNode("password").InnerText = password;            sysKey = Text.MD5(userName + sysKey, 16);
                string url = "http://bbssilk.zsjdc.com/dv_dpo.asp";
                
                //GET
                WebRequest wr = WebRequest.Create(url + "?" + param);
                wr.Method = "GET";
                //wr.ContentType = "application/x-www-form-urlencoded";
                //wr.ContentLength = bs.Length;
                
                //POST发送数据
                /*
                using (StreamWriter sw = new StreamWriter(wr.GetRequestStream(), Encoding.UTF8))
                {
                    sw.Write(doc.OuterXml);
                    sw.Close();
                }
                */            //接收数据
                WebResponse response = wr.GetResponse();
                Stream stream = response.GetResponseStream();
                StreamReader sr = new StreamReader(stream, Encoding.UTF8);
                string result = sr.ReadToEnd();
                sr.Close(); sr.Dispose();
                stream.Close(); stream.Dispose();
                //Response.Write(url + "::" + result);
                //Response.End();
                if (string.IsNullOrEmpty(result))
                    return string.Empty;
                return result;
            }        private string FromUrl
            {
                get
                {
                    string url = Request.QueryString["from"];
                    if (string.IsNullOrEmpty(url)) return string.Format("{0}User/index{1}", CBasic.Web.Page.WebSite, CBasic.Web.Page.FileExtName);
                    return Server.UrlDecode(url);
                }
            }
        }
    }