public override void OnActionExecuting(ActionExecutingContext filterContext) { string actionName = filterContext.ActionDescriptor.ActionName; string controllerName = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName; if (string.IsNullOrEmpty(EventType)) { EventType = "Sys"; } var user = (CCUSER)filterContext.HttpContext.Session.Contents["User"]; string IpAddress = GetIPAddress(); DateTime browseTime = DateTime.Now; string eventName = (string.IsNullOrEmpty(customeEventName)) ? actionName : customeEventName; using (OBLCONTACTCENTEREntities db = new OBLCONTACTCENTEREntities()) { CCEVENTLOG oCCEVENTLOG = new CCEVENTLOG(); oCCEVENTLOG.UserId = (user == null) ? " Anonymous" : user.USERID; oCCEVENTLOG.RequestTime = browseTime; oCCEVENTLOG.IPAddress = IpAddress; oCCEVENTLOG.Controller = controllerName; oCCEVENTLOG.Action = actionName; oCCEVENTLOG.EventName = eventName; oCCEVENTLOG.EventType = EventType; db.CCEVENTLOGs.Add(oCCEVENTLOG); //db.SaveChanges(); } base.OnActionExecuting(filterContext); }
public override string[] GetRolesForUser(string UserId) { using (OBLCONTACTCENTEREntities oEntity = new OBLCONTACTCENTEREntities()) { string[] ret = oEntity.CCROLEs.Where(t => t.CCUSERs.FirstOrDefault(x => x.USERID == UserId) != null).Select(p => p.ROLENAME).ToArray(); return(ret); } }
public override string[] GetAllRoles() { using (OBLCONTACTCENTEREntities oEntity = new OBLCONTACTCENTEREntities()) { string[] ret = oEntity.CCROLEs.Select(x => x.ROLENAME).ToArray(); return(ret); } }
public override bool IsUserInRole(string username, string roleName) { using (OBLCONTACTCENTEREntities db = new OBLCONTACTCENTEREntities()) { CCUSER user = db.CCUSERs.FirstOrDefault(u => u.USERID == username && u.CCROLE.ROLENAME == roleName); if (user != null) { return(true); } else { return(false); } } }
protected override bool AuthorizeCore(HttpContextBase httpContext) { var allowedRoles = Roles; var currentUser = httpContext.User.Identity; using (OBLCONTACTCENTEREntities db = new OBLCONTACTCENTEREntities()) { CCUSER user = db.CCUSERs.FirstOrDefault(u => currentUser.IsAuthenticated && u.USERID == currentUser.Name && u.CCROLE.ROLENAME.Contains(allowedRoles)); if (user != null) { return(true); } else { return(false); } } //return base.AuthorizeCore(httpContext); }