コード例 #1
0
        protected void btnOK_Click(object sender, EventArgs e)
        {
            string   sUid;
            string   sPwd;
            string   sToken    = "";
            bool     isSession = true;
            PageBase myPage    = new PageBase(Page);

            DLLUserService.User myUser = new DLLUserService.User();

            sUid = txtUid.Text.Trim();
            sPwd = txtPwd.Text.Trim();

            if (Request.Form["chLogAuto"] == "1")
            {
                isSession = false;
            }

            try
            {
                //sToken = myUser.Login(ref sUid, sPwd, "192.168.194.105");
                sToken = myUser.Login(ref sUid, sPwd, Request.UserHostAddress);
            }
            catch (Exception ex)
            {
                ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "onekey", "alert('" + GetSoapError(ex) + "');", true);
                return;
            }

            try
            {
                myUser.Logout(myPage.TokenEx);
            }
            catch (Exception ex)
            {
            }

            //写cookie
            myPage.set_UserID(true, sUid);
            myPage.set_Token(isSession, sToken);

            GotoPage();
        }
コード例 #2
0
        //
        protected void Page_Load(object sender, EventArgs e)
        {
            PageBase myPage;

            try
            {
                myPage = new PageBase(this.Page);
            }
            catch (Exception ex)
            {
                ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "onekey", "alert('WebService地址或访问权限配置不正确!');", true);
                trLogin.Visible = false;
                trExit.Visible  = false;
                return;
            }

            lblWelcome.Text = "已登录";

            if (!IsPostBack)
            {
                if (IsLogin(Page))
                {
                    ShowExit(myPage.get_UserID(true));
                }
                else
                {
                    try
                    {
                        DLLUserService.User usr = new DLLUserService.User();
                        string sUserID          = "";
                        string sToken;

                        sToken = usr.Login(ref sUserID, "", Request.UserHostAddress);
                        //sToken = usr.Login(ref sUserID, "", "192.168.194.105");
                        myPage.set_UserID(true, sUserID);
                        myPage.set_Token(true, sToken);
                        if (sToken != "")
                        {
                            ShowExit(sUserID);
                        }
                        else
                        {
                            ShowLogin();
                        }
                    }
                    catch (Exception ex)
                    {
                        if (ex.Message.ToString().IndexOf(" 404 失败") > 0)
                        {
                            ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "onekey", "alert('WebService地址或访问权限配置不正确!');", true);
                            trLogin.Visible = false;
                            trExit.Visible  = false;
                            return;
                        }
                        else
                        {
                            ShowLogin();
                        }
                    }
                }
            }
        }