Beispiel #1
0
        /// <summary>
        /// The application_ start.
        /// </summary>
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);

            //实现自定义的依赖注入控制器
            var container = IocManager.Instance.GetContainer();
            var factory   = new UnityControllerFactory(container);

            ControllerBuilder.Current.SetControllerFactory(factory);

            // api 依赖注入
            var depentdeencyrFactory = new UnityControllerApiFactory(container);

            GlobalConfiguration.Configuration.DependencyResolver = depentdeencyrFactory;

            // 运行应用程序初始化操作
            AppInit.Run();
            ToolkitsHelper.InitAllFunc();

            // 启用EF性能调试工具
            HibernatingRhinos.Profiler.Appender.EntityFramework.EntityFrameworkProfiler.Initialize();

            // 启用Log4Net 日志
            log4net.Config.XmlConfigurator.ConfigureAndWatch(new FileInfo(Server.MapPath("~" + @"/config/Log4Net.config")));
        }
Beispiel #2
0
        public ActionResult Login(string account, string password, string verCode)
        {
            string msg;

            if (string.IsNullOrWhiteSpace(verCode))
            {
                this.ViewBag.msg = "请输入正确的验证码!";
                return(this.View());
            }

            var code = this.TempData["vcode"] as string;

            if (!verCode.Equals(code))
            {
                this.ViewBag.msg = "请输入正确的验证码!";
                return(this.View());
            }

            var user = this.systemServices.UserLogin(account, password, out msg);

            this.ViewBag.msg = msg;
            if (user == null)
            {
                return(this.View());
            }


            try
            {
                var ip      = HttpContext.Request.UserHostAddress;
                var browser = HttpContext.Request.Browser.Browser;
            }
            catch (Exception ex)
            {
                Log.WriteLine(ex);
            }


            // 计算可访问的权限
            foreach (var sysFuncItem in user.FuncItems)
            {
                var roleName = ToolkitsHelper.InitAllFunc().FirstOrDefault(a => a.RoleName == sysFuncItem.ToString());
                if (roleName != null)
                {
                    user.AuthenticationUrl.AddRange(roleName.IncludeUrl);
                }

                if (sysFuncItem.SubSysFunc != null)
                {
                    foreach (var funcSmall in sysFuncItem.SubSysFunc)
                    {
                        var smallRoleName = ToolkitsHelper.InitAllFunc().FirstOrDefault(a => a.RoleName == funcSmall.ToString());
                        if (smallRoleName != null)
                        {
                            user.AuthenticationUrl.AddRange(smallRoleName.IncludeUrl);
                        }
                    }
                }
            }

            UserIdentity.CurrentUser = user;
            return(this.Redirect("/home/index"));
        }