public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            //如果未登录
            if (!filterContext.HttpContext.User.Identity.IsAuthenticated)
            {
                string redirectOnSuccess = filterContext.HttpContext.Request.RawUrl;
                string redirectUrl = string.Format("?ReturnUrl={0}", redirectOnSuccess);
                string loginUrl = FormsAuthentication.LoginUrl + redirectUrl;
                //filterContext.HttpContext.Response.Redirect(loginUrl, true);

                filterContext.Result = new RedirectResult(loginUrl);
            }
            else
            {
                string logUserAccount = UserSession.Current.UserAccount;
                if (string.IsNullOrEmpty(logUserAccount))
                {
                    if (filterContext.HttpContext.Request.Cookies["LoginUserAccount"] != null && filterContext.HttpContext.Request.Cookies["LoginDspName"] != null)
                    {
                        string strUserAccount = filterContext.HttpContext.Request.Cookies["LoginUserAccount"].Value;
                        string strUserDspName = filterContext.HttpContext.Request.Cookies["LoginDspName"].Value;

                        if (!string.IsNullOrEmpty(strUserAccount))
                        {
                            CommonFunction comFun = new CommonFunction();
                            comFun.setSesssionAndCookies(strUserAccount, HttpUtility.UrlDecode(strUserDspName));
                        }
                    }
                }
                //判断是否存在角色
                // 角色包含的可以访问的页面权限是否有权利访问该页面  无权限就跳转到默认无权限页面
                //filterContext.Result = new RedirectResult("/Account/warning");
            }
        }
Esempio n. 2
0
    protected override void OnInitComplete(EventArgs e)
    {
        //如果不是mobile,则跳到提示下载的页面
        if (!User.Identity.IsAuthenticated)
        {
            Response.Redirect("~/Login.aspx");
        }

        CommonFunction comFun = new CommonFunction();
        string logUserAccount = UserSession.Current.UserAccount;
        if (string.IsNullOrEmpty(logUserAccount))
        {
            if (Request.Cookies["LoginUserAccount"] != null && Request.Cookies["LoginDspName"] != null)
            {
                string strUserAccount = Request.Cookies["LoginUserAccount"].Value;
                string strUserDspName = Request.Cookies["LoginDspName"].Value;
                string strUserGroups = (Request.Cookies["LoginUserGroups"] != null) ? Request.Cookies["LoginUserGroups"].Value : "";

                if (!string.IsNullOrEmpty(strUserAccount))
                {
                    comFun.setSesssionAndCookies(strUserAccount, HttpUtility.UrlDecode(strUserDspName), HttpUtility.UrlDecode(strUserGroups));
                }
                else
                {
                    Response.Redirect("~/Login.aspx");
                }
            }
            else
            {
                Response.Redirect("~/Login.aspx");
            }
        }

        //if (!Request.AppRelativeCurrentExecutionFilePath.ToString().ToLower().Contains("default.aspx"))
        //{
        //    if (dtUserPage != null && dtUserPage.Rows.Count > 0 && dtUserPage.Select("Menu_Url ='" + Request.AppRelativeCurrentExecutionFilePath.ToString() + "'").Length <= 0)
        //    {
        //        Response.Redirect("~/WarningPage.aspx");
        //    }
        //}
    }
        public string Login(string userid, string pwd, string remember)
        {
            ViewBag.LoginErrMsg = "";
            if (String.IsNullOrEmpty(userid) || String.IsNullOrEmpty(pwd))
            {
                return "用户名或密码错误,请从新输入!";
            }

            string domain = ConfigurationManager.AppSettings["LdapAuthenticationDomain"].ToString();
            LdapAuthentication ladAuthBP = new LdapAuthentication();
            ViewBag.ErrorMsg = "";
            if (ladAuthBP.IsAuthenticated(domain, userid, pwd) && ladAuthBP.GetStatus())
            {
                Hashtable userInfo = ladAuthBP.GetUserInfo();
                string userDspName = (userInfo.Count > 0) ? userInfo["cn"].ToString() : "";
                FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(1, "LoginCookieInfo", DateTime.Now, DateTime.Now.AddMinutes(60), false, userid); // User data
                string encryptedTicket = FormsAuthentication.Encrypt(authTicket); //加密
                //   存入Cookie
                HttpCookie authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
                authCookie.Expires = authTicket.Expiration;
                Response.Cookies.Add(authCookie);

                if ("true".Equals(remember.ToLower()))//再写入cookie
                {
                    if (Request.Cookies["RememberMe"] == null || String.IsNullOrEmpty(Response.Cookies["RememberMe"].Value))
                    {
                        Response.Cookies["RememberMe"].Value = HttpUtility.UrlEncode(userid, System.Text.Encoding.GetEncoding("gb2312"));
                        Response.Cookies["RememberMe"].Expires = DateTime.Now.AddMonths(1);
                    }
                }
                else
                {
                    if (Response.Cookies["RememberMe"] != null) Response.Cookies["RememberMe"].Expires = DateTime.Now.AddDays(-1);//删除
                }
                CommonFunction comFun = new CommonFunction();
                comFun.setSesssionAndCookies(userid, userDspName);
                return "";// RedirectToAction("Index", "Home");
            }

            return "用户名或密码错误,请从新输入!";
        }
Esempio n. 4
0
    private void Login_ADUser()
    {
        string userid = this.txtUserID.Text.Trim().ToLower();//登录人账户
        string pwd = this.txtPwd.Text.Trim();//登录人密码

        if (String.IsNullOrEmpty(userid) || String.IsNullOrEmpty(pwd))
        {
            this.lblRegMsgPopup.Text = "用户名或密码错误,请从新输入!";
            return;
        }

        string domain = ConfigurationManager.AppSettings["LdapAuthenticationDomain"].ToString();
        LdapAuthentication ladAuthBP = new LdapAuthentication();

        if (ladAuthBP.IsAuthenticated(domain, userid, pwd) && ladAuthBP.GetStatus())
        {
            Hashtable userInfo = ladAuthBP.GetUserInfo();
            string userDspName = (userInfo.Count > 0) ? userInfo["cn"].ToString() : "";
            FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(1, "LoginCookieInfo", DateTime.Now, DateTime.Now.AddMinutes(60), false, userid); // User data
            string encryptedTicket = FormsAuthentication.Encrypt(authTicket); //加密
            //   存入Cookie
            HttpCookie authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
            authCookie.Expires = authTicket.Expiration;
            Response.Cookies.Add(authCookie);

            if (chkRemember.Checked)//再写入cookie
            {
                if (Request.Cookies["RememberMe"] == null || String.IsNullOrEmpty(Response.Cookies["RememberMe"].Value))
                {
                    Response.Cookies["RememberMe"].Value = HttpUtility.UrlEncode(userid, System.Text.Encoding.GetEncoding("gb2312"));
                    Response.Cookies["RememberMe"].Expires = DateTime.Now.AddMonths(1);
                }
            }
            else
            {
                if (Response.Cookies["RememberMe"] != null) Response.Cookies["RememberMe"].Expires = DateTime.Now.AddDays(-1);//删除
            }
            CommonFunction comFun = new CommonFunction();
            comFun.setSesssionAndCookies(userid, userDspName, ladAuthBP.GetGroups());

            this.Response.Redirect("~/Default.aspx");
        }

        this.lblRegMsgPopup.Text = "用户名或密码错误,请从新输入!";
        return;
    }
Esempio n. 5
0
    private void Login_KFCUser()
    {
        //string strUserAccount = this.txtUserID.Text.Trim();//登录人账户
        //string strPwd = this.txtPwd.Text.Trim();//登录人密码
        //CommonFunction comFun = new CommonFunction();

        //strPwd = comFun.setMD5Password(strPwd);//md5加密

        //string resultDspName = comFun.checkLogin(strUserAccount, strPwd);//登录人显示名
        //if (!string.IsNullOrEmpty(resultDspName))
        //{
        //    comFun.setSesssionAndCookies(strUserAccount,resultDspName);
        //    this.Response.Redirect("~/Default.aspx");
        //}
        //else
        //{
        //    this.lblRegMsgPopup.Text = "登录失败!";
        //    return;
        //}

        string strUserAccount = this.txtUserID.Text.Trim();//登录人账户
        string strPwd = this.txtPwd.Text.Trim();//登录人密码
        CommonFunction comFun = new CommonFunction();
        strPwd = comFun.setMD5Password(strPwd);//md5加密

        string strTemp = comFun.checkLogin(strUserAccount, strPwd);
        string resultDspName = strTemp.Split(',')[1];//登录人显示名
        strUserAccount = strTemp.Split(',')[0];
        if (!string.IsNullOrEmpty(resultDspName))
        {
            //System.Web.Security.FormsAuthentication.SetAuthCookie(strUserAccount, false);
            FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(1, "LoginCookieInfo", DateTime.Now, DateTime.Now.AddMinutes(60), false, strUserAccount); // User data
            string encryptedTicket = FormsAuthentication.Encrypt(authTicket); //加密
            //   存入Cookie
            HttpCookie authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
            authCookie.Expires = authTicket.Expiration;
            Response.Cookies.Add(authCookie);

            if (chkRemember.Checked)//再写入cookie
            {
                if (Request.Cookies["RememberMe"] == null || String.IsNullOrEmpty(Response.Cookies["RememberMe"].Value))
                {
                    Response.Cookies["RememberMe"].Value = HttpUtility.UrlEncode(strUserAccount, System.Text.Encoding.GetEncoding("gb2312"));
                    Response.Cookies["RememberMe"].Expires = DateTime.Now.AddMonths(1);
                }
            }
            else
            {
                if (Response.Cookies["RememberMe"] != null) Response.Cookies["RememberMe"].Expires = DateTime.Now.AddDays(-1);//删除
            }

            comFun.setSesssionAndCookies(strUserAccount, resultDspName, "");

            this.Response.Redirect("~/Default.aspx");
            //if (Request.QueryString.ToString().Contains("ReturnUrl") && !String.IsNullOrEmpty(Request.QueryString["ReturnUrl"].ToString()))
            //{
            //    this.Response.Redirect(Request.QueryString["ReturnUrl"].ToString());
            //}
            //else
            //{
            //    this.Response.Redirect("~/Default.aspx");
            //}
        }
        else
        {
            this.lblRegMsgPopup.Text = "登录失败!";
            return;
        }
    }