Exemple #1
0
        public static void EstablecerSesion(string asUsuario, string asPassword)
        {
            HttpSessionStateWrapper loSession = new HttpSessionStateWrapper(HttpContext.Current.Session);

            loSession["sadUsuario"]  = asUsuario;
            loSession["sadPassword"] = asPassword;
        }
 internal static HttpSessionStateWrapper CreateSessionWrapper(HttpSessionState httpSessionState)
 {
     HttpSessionStateWrapper httpSessionStateWrapper = new HttpSessionStateWrapper(httpSessionState);
     //if (httpSessionState.IsNewSession)
     //    httpSessionStateWrapper.NotifyCreated();
     return httpSessionStateWrapper;
 }
    public static bool FuncionAnyContabilidad(HttpContext context)
    {
        //List<string> lstFuncionesUsuario;

        string UserID = context.User.Identity.GetUserId();
        HttpSessionStateBase Session = new HttpSessionStateWrapper(context.Session);

        FacturaPoliContext db = ParseExtensions.GetDatabaseContext(UserID);

        UsuarioModel objUsuario = db.DBUsuarios.SingleOrDefault(r => r.IdentityID == UserID);

        if (objUsuario == null)
        {
            return(false);
        }

        QuickEmisorModel objEmisor = ModuloHelper.GetEmisorSeleccionado(Session, UserID);

        if (objEmisor == null)
        {
            return(false);
        }

        bool hasFuncionesContablesInModulosHabilitados = db.DBModulosHabilitados
                                                         .Where(
            r => r.UsuarioModelID == objUsuario.UsuarioModelID &&
            r.QuickEmisorModelID == objEmisor.QuickEmisorModelID
            ).Any
                                                             (r => r.Funcion.ModuloSistema.ModuloSistemaModelID == ParseExtensions.KeyModuloSistemaContable);

        return(hasFuncionesContablesInModulosHabilitados);
    }
Exemple #4
0
        static public Boolean ValidateAccessUsuario()
        {
            HttpSessionStateBase session = new HttpSessionStateWrapper(HttpContext.Current.Session);

            return(session["userValidated"] != null && session["userValidated"].ToString() == Boolean.TrueString &&
                   session["editarUsuario"] != null && session["editarUsuario"].ToString() == Boolean.TrueString);
        }
Exemple #5
0
        static public void terminateSession()
        {
            HttpSessionStateBase session = new HttpSessionStateWrapper(HttpContext.Current.Session);

            session.Clear();
            session.Abandon();
        }
Exemple #6
0
 /// <summary>
 /// Hàm kiểm tra quyền hạn tài khoản đăng nhập được phép cập nhật thông tin
 /// </summary>
 /// <param name="idMenu">ID menu của trang dựa có trong file menuTools</param>
 /// <param name="soQuyen">Số quyền cập nhật: <para/> 2: Cập nhật <para/> 3: Cập nhật - xóa <para/> 6: Cập nhật - Đọc</param>
 /// <returns>True: Được phép thực thi <para/> false: không được phép</returns>
 public static bool duocCapNhat(string idMenu, string soQuyen)
 {
     try
     {
         if (soQuyen.Equals("6") || soQuyen.Equals("2") || soQuyen.Equals("3") || soQuyen.Equals("7"))
         {
             HttpSessionStateBase Session = new HttpSessionStateWrapper(HttpContext.Current.Session);
             taiKhoan             tkLogin = (taiKhoan)Session["login"];
             if (tkLogin.tenDangNhap != null)
             {
                 string quyenHan = xulyDuLieu.traVeKyTuGoc(tkLogin.nhomTaiKhoan.quyenHan);
                 if (quyenHan.Contains(":" + idMenu + "&" + soQuyen)) //------Nếu như quyền hạn có menu trang cần truy cập
                 {
                     return(true);
                 }
             }
             //-------Chuyển đến trang báo lỗi quyền truy cập khi không có quyền hạn
             HttpContext.Current.Response.Redirect(xulyChung.layTenMien() + "/Home/h_AccessDenied", false);
         }
     }
     catch (Exception ex)
     {
         xulyFile.ghiLoi("Class: xulyChung - Function: duocCapNhat", ex.Message);
     }
     return(false);
 }
        public ActionResult Index()
        {
            //Session
            Session["check"] = "test";
            System.Web.HttpContext.Current.Session["check2"] = "test2";
            var data = (string)System.Web.HttpContext.Current.Session["check2"];
            HttpSessionStateBase datas = new HttpSessionStateWrapper(System.Web.HttpContext.Current.Session);

            datas.Add("check3", "test3");

            //Hiddenfield
            var model = new DemoModel {
                Property1 = 10,
                Property2 = 20
            };

            //Cookies

            //ViewData
            ViewData.Add(new KeyValuePair <string, object>("", "10"));

            //ViewBag

            //TempData
            //TempData.Add("Count",10);
            return(View(model));
        }
Exemple #8
0
        public static string ReInit()
        {
            HttpSessionStateBase session = new HttpSessionStateWrapper(System.Web.HttpContext.Current.Session);

            session.Clear();
            session.Abandon();
            return(session.SessionID);
        }
Exemple #9
0
        private static WxeFunctionStateManager CreateWxeFunctionStateManager()
        {
            var session        = HttpContext.Current.Session;
            var sessionWrapper = new HttpSessionStateWrapper(session);

            Assertion.IsTrue(ReferenceEquals(session.SyncRoot, sessionWrapper.SyncRoot));
            return(new WxeFunctionStateManager(sessionWrapper));
        }
Exemple #10
0
        /// <summary>
        /// Hàm thiết lập tham số vào session
        /// </summary>
        /// <param name="page">URL trang cần chuyển đến</param>
        /// <param name="request">Tham số cần lưu trữ vào Session</param>
        public static void cauHinhSession(string page, string request)
        {
            HttpSessionStateBase Session = new HttpSessionStateWrapper(HttpContext.Current.Session);
            string param = "page=" + page + "|request=" + request;

            //------Thiết lập lại session
            Session.Remove("urlAction"); Session.Add("urlAction", "");
            Session["urlAction"] = param;
        }
Exemple #11
0
        /// <summary>
        /// hàm lấy tên đăng nhập hiện hành có trong session
        /// </summary>
        /// <returns>Tên đăng nhập hiện hành</returns>
        public static string layTenDangNhap()
        {
            string kq = "";
            HttpSessionStateBase Session = new HttpSessionStateWrapper(HttpContext.Current.Session);
            taiKhoan             tkLogin = (taiKhoan)Session["login"];

            kq = tkLogin.tenDangNhap;
            return(kq);
        }
Exemple #12
0
        /// <summary>
        /// Hàm nhận tham số từ sesison request để xác định tham số cần thực hiện....
        /// </summary>
        /// <returns>Chuỗi tham số</returns>
        public static string nhanThamSoTrongSession()
        {
            //---------Lấy session
            HttpSessionStateBase Session = new HttpSessionStateWrapper(HttpContext.Current.Session);
            string urlAction             = (string)Session["urlAction"]; //urlAction có dạng: page=tv_ChinhSuaThanhVien|request=maTV

            //-----Xử lý request trong session
            urlAction = urlAction.Split('|')[1];           //urlAction có dạng: request=maTV
            urlAction = urlAction.Replace("request=", ""); //urlAction có dạng: maTV
            return(urlAction);
        }
Exemple #13
0
        public static string Usuario()
        {
            HttpSessionStateWrapper loSession = new HttpSessionStateWrapper(HttpContext.Current.Session);

            string loUsuario = string.Empty;

            if (loSession["sadUsuario"] != null)
            {
                loUsuario = loSession["sadUsuario"].ToString();
            }

            return(loUsuario);
        }
Exemple #14
0
        public static string Password()
        {
            HttpSessionStateWrapper loSession = new HttpSessionStateWrapper(HttpContext.Current.Session);

            string loPassword = string.Empty;

            if (loSession["sadPassword"] != null)
            {
                loPassword = loSession["sadPassword"].ToString();
            }

            return(loPassword);
        }
Exemple #15
0
    protected void Page_Load(object sender, EventArgs e)
    {
        HttpSessionStateBase sessionBase = new HttpSessionStateWrapper(Session);

        RP.CurrentSession = sessionBase;
        LiveIDAuthenticationResponse codeResp = (LiveIDAuthenticationResponse)RP.parseAuthenticationResponse(HttpContext.Current.Request);

        if (codeResp == null)
        {
            return;
        }
        RP.SignInRP(codeResp);
    }
Exemple #16
0
        public static void CerrarSesion()
        {
            HttpSessionStateWrapper loSession = new HttpSessionStateWrapper(HttpContext.Current.Session);

            if (loSession["sadUsuario"] != null && loSession["sadPassword"] != null)
            {
                LimpiarSesion(loSession);
            }
            else
            {
                LimpiarSesion(loSession);
            }
        }
Exemple #17
0
        public static string getSessionID()
        {
            var ret = "";
            HttpSessionStateBase session = new HttpSessionStateWrapper(System.Web.HttpContext.Current.Session);

            try
            {
                ret = session.SessionID;
            }
            catch (Exception ex)
            {
            }
            return(ret);
        }
Exemple #18
0
        //

        //Get session items
        private List <CompareItem> GetSessionItems()
        {
            try
            {
                var items = new HttpSessionStateWrapper(System.Web.HttpContext.Current.Session).Contents[sessionKey] as List <CompareItem>;
                if (items == null)
                {
                    return(new List <CompareItem>());
                }
                else
                {
                    return(items);
                }
            }
            catch
            {
                return(new List <CompareItem>());
            }
        }
Exemple #19
0
        public static object get(string key)
        {
            HttpSessionStateBase session = new HttpSessionStateWrapper(System.Web.HttpContext.Current.Session);
            object returnValue           = null;

            try
            {
                if (session != null)
                {
                    if (session[key] != null)
                    {
                        returnValue = session[key];
                    }
                }
            }
            catch (Exception ex) {
            }
            return(returnValue);
        }
Exemple #20
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string mode = Request.Params["openid.mode"];

            if (!String.IsNullOrEmpty(mode))
            {
                if (!expecting_redir)
                {
                    return;
                }

                expecting_redir = false;

                HttpSessionStateBase sessionBase = new HttpSessionStateWrapper(Session);

                RP.CurrentSession = sessionBase;

                YahooAuthenticationResponse resp = RP.ParseAuthenticationResponse(Request);

                if (resp == null)
                {
                    return;
                }

                notLoggedIn.Visible = false;
                LoggedIn.Visible    = true;

                if (RP.SignInRP(resp) != null)
                {
                    logged_id.InnerHtml = String.Format("Your ID is {0}", Request.Params["openid.identity"]);
                }
                else
                {
                    logged_id.InnerHtml = String.Format("Verification Failed");
                }
            }
            else
            {
                notLoggedIn.Visible = true;
                LoggedIn.Visible    = false;
            }
        }
        public static IdentityUser GetCurrentlyLoggedInUser(HttpSessionStateBase session = null)
        {
            try
            {
                if (session == null && HttpContext.Current != null && HttpContext.Current.Session != null)
                {
                    session = new HttpSessionStateWrapper(HttpContext.Current.Session);
                }
                if (session != null)
                {
                    IdentityUser user = session[SS_CURRENT_USER] as IdentityUser;
                    if (user == null)
                    {
                        var principal = HttpContext.Current.User as ClaimsPrincipal;
                        if (principal != null && principal.Identity.IsAuthenticated)
                        {
                            IdentityUserDAO.InstitutionCode = InstitutionCode;
                            var userId = HttpContext.Current.User.Identity.GetUserId <long>();
                            if (userId > 0)
                            {
                                user = IdentityUserDAO.Retrieve(userId);
                            }
                            if (user == null)
                            {
                                throw new LogOutUserException($"Called WebUtilities.GetCurrentlyLoggedInUser(): Failed to get user [id: {userId}. instCode: {IdentityUserDAO.InstitutionCode}]");
                            }

                            user.InstitutionCode = IdentityUserDAO.InstitutionCode; //Needful? Maybe not.
                            HttpContext.Current.Session[SS_CURRENT_USER] = user;
                        }
                    }
                    return(user);
                }
                return(null);
            }
            catch (Exception ex) when(!(ex is LogOutUserException))
            {
                Utilities.Logger.Log(ex);
                return(null);
            }
        }
    public static bool FuncionRequerida(HttpContext context, string ComponenteRequerido)
    {
        List <string> lstFuncionesUsuario;
        //if (context.Session["listaFuncionesAccesibles"] == null)
        //{
        string UserID = context.User.Identity.GetUserId();
        HttpSessionStateBase Session = new HttpSessionStateWrapper(context.Session);

        FacturaPoliContext db = ParseExtensions.GetDatabaseContext(UserID);

        //rescata usuario
        UsuarioModel objUsuario = db.DBUsuarios.SingleOrDefault(r => r.IdentityID == UserID);

        if (objUsuario == null)
        {
            return(false);
        }

        //rescata emisor seleccionado
        QuickEmisorModel objEmisor = ModuloHelper.GetEmisorSeleccionado(Session, UserID);

        if (objEmisor == null)
        {
            return(false);
        }
        lstFuncionesUsuario = db.DBModulosHabilitados
                              .Where(r => r.UsuarioModelID == objUsuario.UsuarioModelID && r.QuickEmisorModelID == objEmisor.QuickEmisorModelID)
                              .Select(w => w.Funcion.NombreFuncion).ToList();

        //        context.Session["listaFuncionesAccesibles"] = lstFuncionesUsuario;
        //      }
        //lstFuncionesUsuario = (List<string>)context.Session["listaFuncionesAccesibles"];
        if (lstFuncionesUsuario != null && lstFuncionesUsuario.Contains(ComponenteRequerido, StringComparer.OrdinalIgnoreCase))
        {
            return(true);
        }
        else
        {
            return(false);
        }
    }
Exemple #23
0
        //public static HttpSessionState session { get; set; }

        public static void set(string key, object value)
        {
            HttpSessionStateBase session = new HttpSessionStateWrapper(System.Web.HttpContext.Current.Session);

            try
            {
                if (session != null)
                {
                    if (session[key] != null)
                    {
                        session[key] = value;
                    }
                    else
                    {
                        session.Add(key, value);
                    }
                }
            }catch (Exception ex)
            {
            }
        }
        /// <summary>
        /// Reset the session
        /// </summary>
        /// <param name="sender">
        /// The sender
        /// </param>
        /// <param name="e">
        /// The parameter is not used
        /// </param>
        protected void Session_End(object sender, EventArgs e)
        {
            Logger.Info("ending session ...");
            HttpSessionStateBase sessionBase = new HttpSessionStateWrapper(Session);

            SessionQueryManager.ResetSession(sessionBase);
            try
            {
                foreach (string SessionName in Session.Keys)
                {
                    if (Session[SessionName] != null && Session[SessionName] is SessionImplObject)
                    {
                        ((SessionImplObject)Session[SessionName]).ClearCache();
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex.Message, ex);
            }
        }
Exemple #25
0
 /// <summary>
 /// Hàm kiểm tra quyền hạn tài khoản đăng nhập có được phép truy cập vào trang. <para/>
 /// Nếu không thì trả về true mà không chuyển sang trang báo quyền hạn
 /// </summary>
 /// <param name="idMenu">ID menu của trang dựa có trong file menuTools</param>
 /// <returns>True: Được truy cập <para/> False: không được truy cập</returns>
 public static bool duocTruyCapKhongChuyenTiep(string idMenu)
 {
     try
     {
         HttpSessionStateBase Session = new HttpSessionStateWrapper(HttpContext.Current.Session);
         taiKhoan             tkLogin = (taiKhoan)Session["login"];
         if (tkLogin.tenDangNhap != null)
         {
             string quyenHan = xulyDuLieu.traVeKyTuGoc(tkLogin.nhomTaiKhoan.quyenHan);
             if (quyenHan.Contains(":" + idMenu)) //------Nếu như quyền hạn có menu trang cần truy cập
             {
                 return(true);
             }
         }
     }
     catch (Exception ex)
     {
         xulyFile.ghiLoi("Class: xulyChung - Function: duocTruyCap", ex.Message);
     }
     return(false);
 }
        private static IAuthenticated getAuthenticatedSessionUser()
        {
            HttpSessionStateBase session = new HttpSessionStateWrapper(HttpContext.Current.Session);

            return(session[Reference.KEY_USER_SESSION] as IAuthenticated ?? null);
        }
Exemple #27
0
        public HttpSessionStateBase GetHttpSessionStateBase()
        {
            HttpSessionStateBase sessionStateBase = new HttpSessionStateWrapper(HttpContext.Current.Session);

            return(sessionStateBase);
        }
Exemple #28
0
        /// <summary>
        /// 准备个性化会话工作对象
        /// </summary>
        protected void _PrepareContext()
        {
            _SessionEx        = new HttpSessionStateWrapper(Session, _CurrentTime);
            _SessionEx.Dirty += d =>
            {
                var context = _DTContext <CommonContext>(true);
                switch (d)
                {
                case HttpSessionStateWrapper.Types.Role:
                    var roles = (
                        from r in context.AS_Roles
                        join u in context.AS_UserInRoles on r.RoleId equals u.RoleId
                        select r.RoleName).ToArray();
                    _SessionEx.Set <string[]>(roles, HttpSessionStateWrapper.Keys.RoleIds);
                    _SessionEx.SetDirty(HttpSessionStateWrapper.Types.Role, false);
                    break;

                case HttpSessionStateWrapper.Types.Portlet:

                    // 在全局 portlet 池中筛选出有权限访问的 portlet
                    var portlets = new List <string>();
                    Global.Cache.Portlets.ForEach(p =>
                    {
                        if (Global.Cache.AccessIds.ContainsKey(p.Id))
                        {
                            var accessId = Global.Cache.AccessIds[p.Id];
                            if (AC(accessId.ToString()))
                            {
                                portlets.Add(p.Path);
                            }
                        }
                        else
                        {
                            portlets.Add(p.Path);
                        }
                    });

                    _SessionEx.Set <string[]>(portlets.ToArray(), HttpSessionStateWrapper.Keys.Portlets);
                    _SessionEx.SetDirty(HttpSessionStateWrapper.Types.Portlet, false);
                    break;
                }
            };

            try
            {
                _SessionEx.LastVisitTime            = _CurrentTime;
                _SessionEx.LastVisitUrl             = Request.Url.ToStringEx();
                _SessionEx.LastVisitUrlReferrer     = Request.UrlReferrer.ToStringEx();
                _SessionEx.LastVisitUserAgent       = Request.UserAgent;
                _SessionEx.LastVisitUserHostAddress = Request.UserHostAddress;
                _SessionEx.LastVisitUserHostName    = Request.UserHostName;
            }
            catch
            {
            }

            // 同步当前线程
            _Auth.SynThread(p =>
            {
                _Logined = _SessionEx.Logined;
                if (_Logined)
                {
                    return;
                }

                _Logined            = !p.IsPublic && !p.IsGuest;
                _SessionEx.UserName = p.Identity.Name;
                _SessionEx.UniqueId = p.Id;
                if (_Logined && !_SessionEx.Logined)
                {
                    _SynSession();
                }
            });

            _Util = new UserProfilesRelatedUtil(_SessionEx);
            _DTService.Initialize(_SessionEx, _CurrentTime, Global.Cache);
        }
Exemple #29
0
 private static void LimpiarSesion(HttpSessionStateWrapper aoSession)
 {
     aoSession["sadUsuario"]  = string.Empty;
     aoSession["sadPassword"] = string.Empty;
 }
Exemple #30
0
 public SessionEndEventArgs(HttpSessionStateWrapper sessionState)
 {
     SessionState = sessionState;
 }
Exemple #31
0
 public UserInfo(HttpSessionStateWrapper session)
 (