/// <summary> /// 负责调用autofac框架实现业务逻辑层和数据仓储层程序集中的类型对象的创建 /// 负责创建MVC控制器类的对象(调用控制器中的游蚕构造函数),接管DefaultControllerFactory工作 /// </summary> public static void Register() { //1.0实例化一个autofac的创建容器 var builder = new ContainerBuilder(); //2.0告诉autofac框架,将来要创建控制器类存放在哪个程序集 Assembly controllerAss = Assembly.Load("duo.CRM.Site"); builder.RegisterControllers(controllerAss); //3.0告诉autofac框架注册仓储层所在程序集中的所有类的对象实例 Assembly respAss = Assembly.Load("duo.CRM.Repository"); //创建respAss中的所有类的instance以此类的实现接口存储 builder.RegisterTypes(respAss.GetTypes()).AsImplementedInterfaces(); //4.0告诉autofac框架注册业务逻辑所在程序集中的所有类的对象实例 Assembly serAss = Assembly.Load("duo.CRM.Services"); //创建respAss中的所有类的instance以此类的实现接口存储 builder.RegisterTypes(serAss.GetTypes()).AsImplementedInterfaces(); //builder.RegisterType(typeof(sysFunctionServices)).As(typeof(IsysFunctionServices)); //5.0创建autofac的容器 var container = builder.Build(); //将container对象缓存到HttpRuntime.cache中,并且永久有效 CacheMgr.SetData(Keys.AutofacContainer, container); //Resolve方法可以从autofac容器中获取指定IsysFunctionServices的具体实现类的实体对象 //container.Resolve<IServices.IsysFunctionServices>(); //6.0将MVC的控制器对象实例 交由autofa来创建 DependencyResolver.SetResolver(new AutofacDependencyResolver(container)); }
private void button1_Click(object sender, EventArgs e) { IntList intlist = new IntList(); intlist.Add(1); intlist.Add(2); intlist.Add(3); MessageBox.Show(intlist[0].ToString()); 泛型.StringList slist = new StringList(); slist.Add("100"); MyList <int> glist = new MyList <int>(); glist.Add(200); MessageBox.Show(glist.ToString()); MyList <string> glist1 = new MyList <string>(); glist1.Add("200"); MessageBox.Show(glist1.ToString()); //缓存泛型方法的调用演示 Pig pig = CacheMgr.GetData <Pig>("pigkey"); }
public static void Register() { //TODO:使用autofanc实现的工厂替换MVC底层默认控制器工厂 //TODO:还用autofac将所有的接口初始化 //1.0 实例化autofac的容器创建者的对象 var bulider = new ContainerBuilder(); //2.0 实例化仓储层的所有接口的实现类的对象,以接口和实现类的对象形式存储在autofac容器内存中 //bulider.RegisterType(typeof(sysFunctionRepository)).As(typeof(IsysFunctionRepository)); //bulider.RegisterType(typeof(sysKeyValueRepository)).As(typeof(IsysKeyValueRepository)); bulider.RegisterTypes(Assembly.Load("MD.MES.Repository").GetTypes()).AsImplementedInterfaces(); //3.0 实例化Services(业务逻辑层的接口) //bulider.RegisterType(typeof(sysFunctionServices)).As(typeof(IsysFunctionServices)); //bulider.RegisterType(typeof(sysKeyValueServices)).As(typeof(IsysKeyValueServices)); bulider.RegisterTypes(Assembly.Load("MD.MES.Services").GetTypes()).AsImplementedInterfaces(); //4.0 告诉autofac将来创建控制器类对象的程序集名称为什么 Assembly ass = Assembly.Load("MD.MES.Site"); bulider.RegisterControllers(ass); //5.0 告诉auto发出容器创建者创建一个auto的正真容器对象 var container = bulider.Build(); //6.0 将当前的autofac容器对象存入全局缓存中 CacheMgr.SetData("mesautofaccontainer", container); //6.0 告诉MVC将DefaultControllerFactory替换成autofac中的控制器创建工厂 //将来所有的接口使用container去进行传递 DependencyResolver.SetResolver(new AutofacDependencyResolver(container)); }
//校验用户名密码(对Session匹配,或数据库数据匹配) /// <summary> /// /// </summary> /// <param name="encryptToken"></param> /// <param name="accountID"></param> /// <returns></returns> public static bool ValidateTicket(string encryptToken) { ////解密Ticket //var strTicket = FormsAuthentication.Decrypt(encryptToken).UserData; ////从Ticket里面获取用户名和密码 //var index = strTicket.IndexOf("&"); //string userName = strTicket.Substring(0, index); //string password = strTicket.Substring(index + 1); var token = CacheMgr.Get <User>(encryptToken); if (token != null) { return(true); } #region 只使用于网站身份验证 //取得session,不通过说明用户退出,或者session已经过期 //var token = HttpContext.Current.Session[userName]; //accountID = ""; //if (token == null) //{ // return false; //} #endregion //对比session中的令牌 return(false); }
public void SetCache(string sessionid, DCUser2 dcusr) { Guid gd = Guid.NewGuid(); CacheMgr.Add <string>(CryptoUtils.DecryptTripleDES(sessionid), gd.ToString()); CacheMgr.Add <DCUser2>(gd.ToString(), dcusr); }
// public APIRst GetYdMonitorOfControl(string cmd, int module_id) { APIRst rst = new APIRst(); if (string.IsNullOrEmpty(cmd)) { rst.rst = false; rst.err.code = (int)ResultCodeDefine.Error; rst.err.msg = "请发送指令"; return(rst); } try { //long log_id = bll.YdModuleOnAddCmd(module_id, 0, V0Fun.Ssr1.ToString(), cmd); long log_id = bll.YdModuleOnAddCmd(module_id, 0, V0Fun.Ssr.ToString(), cmd); CommandVModel command = bll.GetYdModuleOnSendCmd(log_id); ListenVModel vm = new ListenVModel(); vm.cfun = ListenCFun.cmd.ToString(); vm.content = JsonHelper.Serialize(command); string msg = ""; rst.rst = CacheMgr.SendCollectVal(vm, out msg); rst.err.msg = msg; } catch (Exception ex) { rst.rst = false; rst.err.code = (int)ResultCodeDefine.Error; rst.err.msg = ex.Message; FileLog.WriteLog("下发指令错误(GetYdMonitorOfControl):" + ex.Message + ex.StackTrace); } return(rst); }
public ActionResult Login(LoginInfo model) { //try //{ // 实体参数合法性验证 if (ModelState.IsValid == false) { return(WriteError("实体验证失败")); } // 检查用户名和密码的正确性 var userinfo = userSer.QueryWhere(u => u.Account == model.ULoginName && u.PassWord == model.ULoginPWD).FirstOrDefault(); if (userinfo == null) { return(WriteError("用户名或者密码错误")); } var c = operathisSer.OperatRecordAdd(null, Convert.ToInt32(Enums.ChildType.登录).ToString(), Session["URL"].ToString(), userinfo, null); if (c > 0) { // 将userinfo存入session Session[Keys.userInfo] = userinfo; //设置SESSION时间 Session.Timeout = 20; //获取IP string ip = GetIpHelper.GetWebClientIp(); //将ip放入session Session[Keys.userIP] = ip; //设置cookie内容和时效 HttpCookie UserInfoCookies = new HttpCookie("UserName"); UserInfoCookies.Value = model.ULoginName; UserInfoCookies.Expires = DateTime.Now.AddDays(20); Response.Cookies.Add(UserInfoCookies); HttpCookie UserPwdCookies = new HttpCookie("UserPwd"); UserPwdCookies.Value = model.ULoginPWD; UserPwdCookies.Expires = DateTime.Now.AddDays(20); Response.Cookies.Add(UserPwdCookies); // 返回登录成功消息 // return WriteSuccess("登录成功"); var chartAliasList = chartAliasSer.QueryWhere(); CacheMgr.SetData("chartAliasList", chartAliasList); //return RedirectToAction("MainPage", "Home"); return(RedirectToAction("Index", "Home")); } return(View(model)); //} //catch (Exception ex) //{ // // 返回异常 // return WriteError(ex); //} }
/// <summary> /// 负责调用autofac框架实现业务逻辑层和数据仓储层程序集中的类型对象的创建 /// 负责创建MVC控制器类的对象(调用控制器中的有参构造函数),接管DefaultControllerFactory的工作 /// </summary> public static void Register() { //实例化一个autofac的创建容器 var builder = new ContainerBuilder(); //告诉Autofac框架,将来要创建的控制器类存放在哪个程序集 (Wchl.CRM.WebUI) Assembly controllerAss = Assembly.Load("Wchl.WMBlog.WebUI"); builder.RegisterControllers(controllerAss); //告诉autofac框架注册数据仓储层所在程序集中的所有类的对象实例 Assembly respAss = Assembly.Load("Wchl.WMBlog.Repository"); //创建respAss中的所有类的instance以此类的实现接口存储 builder.RegisterTypes(respAss.GetTypes()).AsImplementedInterfaces(); //告诉autofac框架注册业务逻辑层所在程序集中的所有类的对象实例 Assembly serpAss = Assembly.Load("Wchl.WMBlog.Services"); //创建serAss中的所有类的instance以此类的实现接口存储 builder.RegisterTypes(serpAss.GetTypes()).AsImplementedInterfaces(); builder.RegisterType <RedisCacheManager>().As <ICacheManager>(); //创建一个Autofac的容器 var container = builder.Build(); //将container对象缓存到HttpRuntime.cache中,并且是永久有效 CacheMgr.SetData(Keys.AutofacContainer, container); //将MVC的控制器对象实例 交由autofac来创建 DependencyResolver.SetResolver(new AutofacDependencyResolver(container)); }
/// <summary> /// Loads the access control rules for the given user's access control group /// </summary> /// <returns>Access control rules for the given user's access control group</returns> AccessControlGroupStructure LoadAccessControl() { if (!_accessControlCache.Exists(_userSignon.DefaultAccessGroupCode.ToString())) { AccessControlGroupStructure accessControlGroup = new AccessControlGroupStructure(); accessControlGroup.AccessGroupCode = _userSignon.DefaultAccessGroupCode; CacheMgr <bool> accessControlRules = new CacheMgr <bool>(); DbCommand dbCmd = _daMgr.DbCmdCacheGetOrAdd(Constants.AccessControlGroupRules, BuildCmdGetAccessControlRulesList); dbCmd.Parameters[_daMgr.BuildParamName(Constants.AccessControlGroupCode)].Value = _userSignon.DefaultAccessGroupCode; DataTable accessRules = _daMgr.ExecuteDataSet(dbCmd, null, null).Tables[0]; foreach (DataRow accessRule in accessRules.Rows) { accessControlGroup.DefaultAccessDenied = Convert.ToBoolean( accessRule[Constants.DefaultAccessDenied]); accessControlGroup.AccessGroupName = accessRule[Constants.AccessControlGroupName].ToString(); if (accessRule[Constants.UIControlCode] != DBNull.Value) { Int32 uiControlCode = Convert.ToInt32(accessRule[Constants.UIControlCode]); bool accessDenied = Convert.ToBoolean(accessRule[Constants.AccessDenied]); accessControlRules.Set(uiControlCode.ToString(), accessDenied); } accessControlGroup.AccessControlRules = accessControlRules; } _accessControlCache.Set(_userSignon.DefaultAccessGroupCode.ToString(), accessControlGroup); } return(_accessControlCache.Get(_userSignon.DefaultAccessGroupCode.ToString())); }
/// <summary> /// 负责调用autofac框架实现业务逻辑层和数据仓储层程序集中的类型对象的创建 /// </summary> public static void Register() { // 1.0 实例化一个autofac的创建容器 var builder = new ContainerBuilder(); // 2.0 告诉Autofac框架,将来要创建的控制器类存放在哪个程序集 (Posco.DC.SCADA) Assembly controllerAss = Assembly.Load("Posco.DC.SCADA"); builder.RegisterControllers(controllerAss); // 3.0 告诉autofac框架注册数据仓储层所在程序集中的所有类的对象实例 Assembly respAss = Assembly.Load("Repository"); // 创建respAss中的所有类的instance以此类的实现接口存储 builder.RegisterTypes(respAss.GetTypes()).AsImplementedInterfaces(); // 4.0 告诉autofac框架注册业务逻辑层所在程序集中的所有类的对象实例 Assembly serAss = Assembly.Load("Services"); // 创建serAss中的所有类的instance以此类的实现接口存储 builder.RegisterTypes(serAss.GetTypes()).AsImplementedInterfaces(); // 5.0 创建一个Autofac的容器 var container = builder.Build(); // 5.0.1 将container对象缓存到HttpRuntime.cache中,并且是永久有效 CacheMgr.SetData(Keys.AutofacContainer, container); // 6.0 将MVC的控制器对象实例 交由autofac来创建 DependencyResolver.SetResolver(new AutofacDependencyResolver(container)); }
public IHttpActionResult LogIn(string userName, string password, int type) { var c = HttpContext.Current.Items["accountID"] as string; SimpleResult result = new SimpleResult(); var item = doctorInforService.GetDoctorInfor(userName, password, type); if (userName != "123" && password != "123") { result.Status = Result.FAILURE; result.Msg = "用户名或密码错误"; return(Json(result)); } FormsAuthenticationTicket token = new FormsAuthenticationTicket(0, userName, DateTime.Now, DateTime.Now.AddHours(1), true, string.Format("{0}&{1}", item.accountID, password), FormsAuthentication.FormsCookiePath); //返回登录结果、用户信息、用户验证票据信息 var Token = FormsAuthentication.Encrypt(token); //将身份信息保存在session中,验证当前请求是否是有效请求 CacheMgr.Insert(Token, item, CacheType.Token); result.Resource = Token; return(Json(result)); }
/// <summary> /// 统一验证Session[Keys.uinfo]如果为null则跳转到登陆页 /// </summary> /// <param name="filterContext"></param> public override void OnActionExecuting(ActionExecutingContext filterContext) { //0.0判断是否有贴跳过登录检查的特性标签 if (filterContext.ActionDescriptor.ControllerDescriptor.IsDefined(typeof(SkipCheckLogin), false)) { return; } if (filterContext.ActionDescriptor.IsDefined(typeof(SkipCheckLogin), false)) { return; } //1.0 判断session是否为null if (filterContext.HttpContext.Session[Keys.uinfo] == null) { //1.0.1 查询cookie[Keys.Ismemeber]是否不为null,如果成立则模拟用户的登录,再将用户实体数据存入session[Keys.uinfo]中 if (filterContext.HttpContext.Request.Cookies[Keys.IsMember] != null) { //1.0 取出cookie中存入的uid的值 string uid = filterContext.HttpContext.Request.Cookies[Keys.IsMember].Value; uid = DESEncrypt.Decrypt(uid); //2.0 根据uid查询出用户的实体 //2.0.1 从缓存中获取autofac的容器对象 var cont = CacheMgr.GetData <IContainer>(Keys.AutofacContainer); //2.0.2 找autofac容器获取IsysUserInfoServices接口的具体实现类的对象实例 IsysUserInfoServices userSer = cont.Resolve <IsysUserInfoServices>(); //2.0.3 根据userSer 集合uid查询数据 int iuserid = int.Parse(uid); var userinfo = userSer.QueryWhere(c => c.uID == iuserid).FirstOrDefault(); if (userinfo != null) { //2.0.4 将userinfo存入session filterContext.HttpContext.Session[Keys.uinfo] = userinfo; } else { ToLogin(filterContext); } } else { //2.0 跳转到登录页面 // filterContext.HttpContext.Response.Redirect("/admin/login/login"); //ContentResult cr = new ContentResult(); //cr.Content = "<script>alert('您未登录');window.location='/admin/login/login';</script>"; ToLogin(filterContext); } } base.OnActionExecuting(filterContext); }
public APIResult GetCollectValue(List <ApiVar> var) { APIResult rst = new APIResult(); bool cc = CacheMgr.SendCollectVal(var); rst.Code = cc == true ? 0 : -1; rst.Msg = cc == true ? "成功" : "失败"; rst.Data = ""; return(rst); }
public static void RunTest() { CacheMgr <int> cacheMgr = new CacheMgr <int>(); cacheMgr.Add("Testing", getTestingValue, 18); while (Console.Read() != 'x') { Console.WriteLine(cacheMgr.Get("Testing")); } }
public IHttpActionResult Test(string Token) { var c = Token; var d = CacheMgr.GetData <DoctorInfor>(c); var item = doctorInforService.GetDoctorInfor("1"); SimpleResult result = new SimpleResult(); result.Resource = item; return(Json(result)); }
/// <summary> /// 负责验证Session[Keys.Uinfo]是否为null,如果为null则直接跳转到登录页面 /// </summary> /// <param name="filterContext"></param> public override void OnActionExecuting(HttpActionContext filterContext) { //0.0 判断控制器类或者action是否有贴SkipCheckLogin标签,如果有贴则阻断下面代码的运行 if (filterContext.ControllerContext.ControllerDescriptor.GetCustomAttributes <SkipCheckLoginAttribute>().Count == 1) { return; } if (filterContext.ActionDescriptor.GetCustomAttributes <SkipCheckLoginAttribute>().Count == 1) { return; } //1.0 判断session如果为空则跳转 if (HttpContext.Current.Session[Keys.Uinfo] == null) { //1.0 第一种提醒方式,体验不好,因为会导致页面泛白 //filterContext.HttpContext.Response.Write("<script>alert('您未登录');window.location='/admin/login/login'</script>"); //2.0 判断如果cookie中的数据不为空,则应该取出其中的用户主键去sysuserinfo表中再次获取实体 //存入session if (HttpContext.Current.Request.Cookies[Keys.IsRemember] != null) { //2.0.1 获取用户主键 string userid = HttpContext.Current.Request.Cookies[Keys.IsRemember].Value; //2.0.2 根据userid去访问sysuserinfo获取数据实体 //2.0.2.1 从全局缓存中获取autofac的容器对象 IContainer autofac = CacheMgr.GetData <IContainer>(Keys.autofaccontainer); //2.0.2.2 从autofac容器中获取IsysUserInfoServices的实现类的对象实例 IsysUserInfoServices userSer = autofac.Resolve <IsysUserInfoServices>(); int uid = int.Parse(userid); var userinfo = userSer.QueryWhere(c => c.uID == uid).FirstOrDefault(); //3.0 判断userinfo是否为null if (userinfo == null) { ToLogin(filterContext); } else { //4.0 将userinfo实体对象存入session filterContext.HttpContext.Session[Keys.Uinfo] = userinfo; } } else { //统一跳转 ToLogin(filterContext); } } }
private void GetYdModelsSendCmd(DataTable dtSource) { foreach (DataRow dr in dtSource.Rows) { CommandVModel cmd = ModelHandler <CommandVModel> .FillModel(dr); ListenVModel vm = new ListenVModel(); vm.cfun = ListenCFun.cmd.ToString(); vm.content = JsonHelper.Serialize(cmd); CacheMgr.BeginSend(vm); } }
/// <summary> /// 统一验证session【keys.uinfo】如果是null跳转到登录页 /// </summary> /// <param name="filterContext"></param> public override void OnActionExecuting(ActionExecutingContext filterContext) { //判断是否有贴跳过登录检查的特性标签 if (filterContext.ActionDescriptor.ControllerDescriptor.IsDefined(typeof(SkipCheckLogin), false)) { return; } if (filterContext.ActionDescriptor.IsDefined(typeof(SkipCheckLogin), false)) { return; } if (filterContext.HttpContext.Session[Keys.uinfo] == null) { //1.0查询cookie【keys.Ismember]是否为空,如果成立则模拟用户的登录, //在将用户实体数据存入session[keys.uinfo】中 if (filterContext.HttpContext.Request.Cookies[Keys.IsMember] != null) { //1.0取出cookie中存入的uid的值 string uid = filterContext.HttpContext.Request.Cookies[Keys.IsMember].Value; //2.0根据uid查询出实体 //2.00先从缓存中获取autofac的容器对象 var cont = CacheMgr.GetData <IContainer>(Keys.AutofacContainer); //2.01找autofac容器获取IsysUserInfoServices IsysUserInfoServices userSer = cont.Resolve <IsysUserInfoServices>(); //2.03根据userser集合uid查询数据 int iuserid = int.Parse(uid); var userinfo = userSer.QueryWhere(c => c.uID == iuserid).FirstOrDefault(); if (userinfo != null) { filterContext.HttpContext.Session[Keys.uinfo] = userinfo; } else { ToLogin(filterContext); } } ////法一: // filterContext.HttpContext.Response.Redirect("/Admin/Login/Login"); //法二: //ContentResult cr = new ContentResult(); //cr.Content = "<script>alert('您未登录');window.location='/Admin/Login/Login'</script>"; //filterContext.Result = cr; else { ToLogin(filterContext); } } base.OnActionExecuting(filterContext); }
public override void OnActionExecuting(ActionExecutingContext filterContext) { //0.0判断是否有贴跳过权限检查的特性标签 if (filterContext.ActionDescriptor.ControllerDescriptor.IsDefined(typeof(SkipCheckPermiss), false)) { return; } if (filterContext.ActionDescriptor.IsDefined(typeof(SkipCheckPermiss), false)) { return; } //1.0 获取当前触发此OnActionExecuting的aciton string actionName = filterContext.ActionDescriptor.ActionName.ToLower(); //2.0 控制名称 string controlerName = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName.ToLower(); //3.0 获取区域的名称 string areaName = string.Empty; if (filterContext.RouteData.DataTokens.ContainsKey("area")) { areaName = filterContext.RouteData.DataTokens["area"].ToString().ToLower(); } //4.0 根据上面的三个成员的值作为条件去当前用户的权限按钮缓存数据查找,如果没有找到则表示没有权限 //2.0.1 从缓存中获取autofac的容器对象 var cont = CacheMgr.GetData <IContainer>(Keys.AutofacContainer); IsysPermissListServices iperSer = cont.Resolve <IsysPermissListServices>(); var list = iperSer.GetFunctionsForUserByCache(UserMgr.GetCurrentUserInfo().uID); var isOK = list.Any(c => c.mArea.ToLower() == areaName && c.mController.ToLower() == controlerName && c.fFunction.ToLower() == actionName); if (isOK == false) { isOK = list.Any(c => c.mArea.ToLower() == areaName && c.mController.ToLower() == controlerName && c.mAction.ToLower() == actionName); } if (isOK == false)//无权限 { ToLogin(filterContext); } }
public static sysUserInfo GetUserByID(object userid) { if (userid == null) { return(new sysUserInfo() { }); } int iuser = int.Parse(userid.ToString()); var autofac = CacheMgr.GetData <IContainer>(Keys.AutofacContainer); IsysUserInfoServices userSer = autofac.Resolve <IsysUserInfoServices>(); return(userSer.QueryWhere(c => c.uID == iuser).FirstOrDefault()); }
public static sysUserInfo GetCurrentUserInfo() { if (HttpContext.Current.Request.Cookies[Keys.uinfo] != null) { string sessionId = HttpContext.Current.Request.Cookies[Keys.uinfo].Value; //从缓存中获取autofac的容器对象 var cont = CacheMgr.GetData <IContainer>(Keys.AutofacContainer); //获取到依赖注入数据 ICacheManager cacheManager = cont.Resolve <ICacheManager>(); return(cacheManager.Get <sysUserInfo>(sessionId)); } return(new sysUserInfo() { }); }
/// <summary> /// 下发命令数据 /// </summary> /// <param name="tags"></param> /// <param name="dataValue"></param> /// <returns></returns> public APIRst SendVal(List <string> tags, string dataValue) { List <object> dd = new List <object>(); APIRst rst = new APIRst() { rst = true }; try { DataTable dtInfo = bll.GetTagInfo(string.Join(",", tags.ToArray())); foreach (var k in tags) { DataRow[] arr = dtInfo.Select("LpszDbVarName='" + k + "'"); if (arr.Count() == 0) { dd.Add(new { tag = k, rst = false, msg = "没有此采集点" }); continue; } CommandVModel cmd = ModelHandler <CommandVModel> .FillModel(arr[0]); cmd.Action = 1; cmd.LpszDbVarName = CommFunc.ConvertDBNullToString(arr[0]["TagName"]); cmd.DataValue = dataValue; cmd.IsNDb = true; bll.UpdateMapDataVal(cmd.Module_id, cmd.Fun_id, cmd.DataValue); // ListenVModel vm = new ListenVModel() { cfun = ListenCFun.cmd.ToString(), content = JsonHelper.Serialize(cmd) }; string msg = ""; bool rr = CacheMgr.SendCollectVal(vm, out msg); dd.Add(new { tag = k, rst = rr, msg = msg }); } rst.data = dd; } catch (Exception ex) { rst.rst = false; rst.data = ""; rst.err = new APIErr() { code = -1, msg = ex.Message }; } return(rst); }
public override void OnActionExecuting(ActionExecutingContext filterContext) { //1.0 判断如果贴有 [SkipCheckLogin]则跳过登录检查 if (filterContext.ActionDescriptor.ControllerDescriptor.IsDefined(typeof(SkipCheckLoginAttribute), false)) { return; } if (filterContext.ActionDescriptor.IsDefined(typeof(SkipCheckLoginAttribute), false)) { return; } if (filterContext.HttpContext.Session[Keys.uinfo] == null) { //1.0 判断cookie是否有值 if (filterContext.HttpContext.Request.Cookies[Keys.isremember] == null) { //2.0 跳转到登录页面 ToLogin(filterContext); } else { //3.0 获取cookie中存好的用户id string uid = filterContext.HttpContext.Request.Cookies[Keys.isremember].Value; //4.0 存全局缓存中获取autofac容器对象 var container = CacheMgr.GetData <IContainer>(Keys.autofac); //4.0 根据uid去表sysuserinfo中查询用户对象重新赋值给Session[Keys.uinfo] //IsysUserInfoServices userServics = container.Resolve<IsysUserInfoServices>(); //int iuserid = uid.AsInt(); //var userinfo = userServics.QueryWhere(c => c.uID == iuserid).FirstOrDefault(); //if (userinfo == null) //{ // ToLogin(filterContext); //} //else //{ // filterContext.HttpContext.Session[Keys.uinfo] = userinfo; // //设置缓存 // container.Resolve<IsysPermissListServices>().GetPermissListByUid(userinfo.uID); //} } } }
public static void Register() { //1.0 构造一个autofac的buider容器 var builder = new ContainerBuilder(); //2.0 告诉AutoFac 的控制器工厂,控制器类的创建去哪些程序集中查找 //2.0.1 从当前运行的bin目录下加载itcast.crm16.Site.dll Assembly controllerAss = Assembly.Load("itcast.crm16.Site"); builder.RegisterControllers(controllerAss); //3.0 告诉autofac容器,创建数据仓储项目中的所有类的对象实体,以接口的形式存储 //3.0.1反射扫描itcast.crm16.Repository.dll所有的类 Assembly respAssems = Assembly.Load("itcast.crm16.Repository"); Type[] respTypes = respAssems.GetTypes(); builder.RegisterTypes(respTypes).AsImplementedInterfaces(); #region 单个类的注册方式写法,可以用于调试 //builder.RegisterType(typeof(sysFunctionRepository)).As(typeof(IsysFunctionRepository)); //builder.RegisterType(typeof(sysKeyValueRepository)).As(typeof(IsysKeyValueRepository)); //builder.RegisterType(typeof(sysFunctionServices)).As(typeof(IsysFunctionServices)); //builder.RegisterType(typeof(sysKeyValueServices)).As(typeof(IsysKeyValueServices)); #endregion //4.0 告诉autofac容器,创建业务逻辑项目中的所有类的对象实体,以接口的形式存储 //4.0.1反射扫描itcast.crm16.Services.dll所有的类 Assembly serAssems = Assembly.Load("itcast.crm16.Services"); Type[] serTypes = serAssems.GetTypes(); builder.RegisterTypes(serTypes).AsImplementedInterfaces(); //5.0 创建一个真正的autofac的工作容器 IContainer container = builder.Build(); //5.0.1 将container存入全局缓存对象HttpRuntime.Cache[Keys.autofac]中 CacheMgr.SetData(Keys.autofac, container); // 从Autofac容器内部根据指定的接口 IsysFunctionServices 获取其实现类的对象实例 //var obj = container.Resolve<IsysFunctionServices>(); //6.0 将当前的容器中的控制器工厂替换MVC默认的控制器工厂,此处使用的是将autofac工作容器交给mvc底层 DependencyResolver.SetResolver(new AutofacDependencyResolver(container)); }
/// <summary> /// 将用户权限按钮进行缓存操作 /// </summary> /// <param name="uid"></param> /// <returns></returns> public List <Usp_GetFunctionsForUsers_Result> GetFunctionsForUserByCache(int uid) { //缓存key一定是每个用户有一个,不重复 string cacheKey = Keys.PermissFunctionsForUser + uid; //1.0根据用户获取其权限按钮数据 object data = Common.CacheMgr.GetData <List <Usp_GetFunctionsForUsers_Result> >(cacheKey); if (data == null) { //从数据库获取一份权限按钮数据 var plist = _baseDal.RunProc <Usp_GetFunctionsForUsers_Result>("Usp_GetFunctionsForUsers " + uid); //将数据加入缓存 CacheMgr.SetData(cacheKey, plist); data = plist; } return(data as List <Usp_GetFunctionsForUsers_Result>); }
// #region 针对 此表的 特殊操作 写在此处 // /// <summary> // /// 负责用户权限按钮进行数据缓存操作,以及以后直接从缓存中使用 // /// </summary> // /// <param name="userid"></param> // /// <returns></returns> // public List<CRM.Model.Usp_GetFunctionsForUser15_Result> GetFuctionsForUserByCache(int userid) // { // //注意: 缓存中的key 一定是每个用户有一个,彼此不重复 // string cachekey = Keys.PermissFuctionsForUser + userid; // //1.0 从缓存中 根据户用获取其权限数据 // object data = CacheMgr.GetData<List<CRM.Model.Usp_GetFunctionsForUser15_Result>>(cachekey); // if (data == null) // { // //从数据库获取一份权限按钮数据 // var prmisslist = baseDal.RunProc<CRM.Model.Usp_GetFunctionsForUser15_Result> ("Usp_GetFunctionsForUser15" , userid); // // 将数据加入缓存 // CacheMgr.SetData(cachekey, prmisslist); // return prmisslist; // } // return data as List<CRM.Model.Usp_GetFunctionsForUser15_Result>; // } // #endregion #region 针对此表的特殊操作写在此处 /// <summary> /// 负责将用户权限按钮数据进行缓存操作,以及以后直接从缓存中获取 /// </summary> /// <param name="userid"></param> /// <returns></returns> public List <Usp_GetFunctionsForUser15_Result> GetFuctionsForUserByCache(int userid) { //注意:缓存key一定是每个用户有一个,彼此不重复 string cacheKey = Keys.PermissFuctionsForUser + userid; //1.0 从缓存中根据用户获取其权限按钮数据 object data = CacheMgr.GetData <List <Usp_GetFunctionsForUser15_Result> >(cacheKey); if (data == null) { //从数据库获取一份权限按钮数据 var prmisslist = baseDal.RunProc <Usp_GetFunctionsForUser15_Result>("Usp_GetFunctionsForUser15 " + userid); //将数据加入缓存 CacheMgr.SetData(cacheKey, prmisslist); return(prmisslist); } return(data as List <Usp_GetFunctionsForUser15_Result>); }
/// <summary> /// 设置邮件接口信息 /// </summary> /// <param name="MailFrom">邮件发送人</param> /// <param name="MailSmtpHost">邮件服务器地址</param> /// <param name="MailSmtpPassword">邮件登陆密码</param> /// <param name="MailSmtpUser">邮件登陆名</param> /// <returns></returns> public APIRst SetMailConfig(string MailFrom, string MailSmtpHost, string MailSmtpPassword, string MailSmtpUser) { APIRst rst = new APIRst(); try { if (string.IsNullOrEmpty(MailFrom)) { throw new Exception(" 邮件发送人不能为空"); } if (string.IsNullOrEmpty(MailSmtpHost)) { throw new Exception(" 邮件服务器地址不能为空"); } if (string.IsNullOrEmpty(MailSmtpPassword)) { throw new Exception(" 邮件登陆密码不能为空"); } if (string.IsNullOrEmpty(MailSmtpUser)) { throw new Exception(" 邮件登陆名不能为空"); } rst.data = bll.SetMailConfig(MailFrom, MailSmtpHost, MailSmtpPassword, MailSmtpUser); WebConfig.GetSysConfig(); ListenVModel vm = new ListenVModel(); vm.cfun = ListenCFun.config.ToString(); vm.content = ""; CacheMgr.BeginSend(vm); } catch (Exception ex) { rst.rst = false; rst.err.code = (int)ResultCodeDefine.Error; rst.err.msg = ex.Message; FileLog.WriteLog("系统配置-短信接口信息错误(SetAlarmCfg):" + ex.Message + ex.StackTrace); } return(rst); }
/// <summary> /// 负责调用 autofac框架实现业务逻辑 和 数据仓储层程集中的类型对象的创建 /// 负责创建MVC控制器类的对象(调用控制器中的有残构造函数) , 接管DefaultControllerFactory的工作 /// </summary> public static void Register() { // 1.0 实例化autofac的创建容器 var bulider = new Autofac.ContainerBuilder(); // 2.0 告诉AutoFac 框架, 将来要创建的控制器类存放在哪个程序集(CRM.Site) Assembly controllerAss = Assembly.Load("CRM.Site"); bulider.RegisterControllers(controllerAss); // 3.0 告诉 autofac注册仓储层所在程序集中 所有类的对象的 对象实例 Assembly respAss = Assembly.Load("CRM.Repository"); //创建respAss中所有类 instance 以此的实现接口 存储 bulider.RegisterTypes(respAss.GetTypes()).AsImplementedInterfaces();//.InstancePerHttpRequest(); // 4.0 告诉 autofac注册业务逻辑层所在程序集中 所有类的对象的 对象实例 Assembly serAss = Assembly.Load("CRM.Services"); //创建respAss中所有类 instance 以此的实现接口 存储 bulider.RegisterTypes(serAss.GetTypes()).AsImplementedInterfaces(); //.InstancePerHttpRequest(); // 5.0 创建一个autofac 的容器 var container = bulider.Build(); // 5.01 将container 对象 缓存到 httpRuntime.cache 中, 并且 永久有效 CacheMgr.SetData(Keys.AutofacContainer, container); // Resolve 方法可以从autofac 容器中获取IsysuserInfoSerices 的 具体实现类的实体对象 // 6.0 将MVC的控制器对象实例 交由autofac来创建 DependencyResolver.SetResolver(new AutofacDependencyResolver(container)); }
public void Start() { // Caching.CleanCache(); instance = this; DontDestroyOnLoad (this.gameObject); // if (!mustBeData) { // mustBeData = MiniJsonExtensions.hashtableFromJson(mustBeDownLoad.text); // // } // if (mustBeData) { // serverURL = mustBeData["serverURL"]; // } // mustBeData = Json.Deserialize(mustBeDownLoad.text); loadSceneDc = new Hashtable (); prbDc = new Hashtable (); }
public override void OnActionExecuting(ActionExecutingContext filterContext) { //0.0 //判断action方法所在的控制器是否有贴 if (filterContext.ActionDescriptor.ControllerDescriptor.IsDefined(typeof(SkipCheckPermissAttribute), false)) { return; } //判断action方法是否有贴 if (filterContext.ActionDescriptor.IsDefined(typeof(SkipCheckPermissAttribute), false)) { return; } //1.0 获取action名称 string actionName = filterContext.ActionDescriptor.ActionName.ToLower(); //2.0 获取控制器名称 string ctrlName = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName.ToLower(); //3.0 获取区域名称 string areaName = string.Empty; if (filterContext.RouteData.DataTokens.ContainsKey("area")) { areaName = filterContext.RouteData.DataTokens["area"].ToString().ToLower(); } //4.0 根据上述三个条件去用户权限数据缓存中查询 //4.0.1 获取缓存数据 var container = CacheMgr.GetData <IContainer>(Keys.autofac); //var permissList = container.Resolve<IServices.IsysPermissListServices>().GetPermissListByUid(UserMgr.GetUserInfo().uID); //4.0.2 去permissList中查询一下当前请求的action方法是否存在 ////bool isOk = permissList.Any(c => c.mArea.ToLower() == areaName // && c.mController.ToLower() == ctrlName // && c.fFunction.ToLower() == actionName); //如果没有权限 if (!true) { //5.0 判断是否为ajax请求 if (filterContext.HttpContext.Request.IsAjaxRequest()) { JsonResult json = new JsonResult(); json.Data = new { status = 2, msg = "没有权限" }; json.JsonRequestBehavior = JsonRequestBehavior.AllowGet; filterContext.Result = json; } else { //浏览器请求 ViewResult view = new ViewResult(); view.ViewName = "/Views/Shared/NoPermiss.cshtml"; filterContext.Result = view; } } }
public void ClearCache(string sessionid) { CacheMgr.Clear(CryptoUtils.DecryptTripleDES(sessionid)); }