protected PathServerUtility()
        {
            IHostingEnvironment val = ServiceCollectionExtension.Get <IHostingEnvironment>();

            _HostingEnvironment  = val;
            _WebPhysicalPath     = val.WebRootPath;
            _ContentPhysicalPath = val.ContentRootPath;
            if (ServiceCollectionExtension.HttpContext == null)
            {
                _WebVirtualPath = "/";
                _AbsoluteUrl    = "/";
            }
            else
            {
                HttpRequest val2     = ServiceCollectionExtension.HttpContext.Request;
                PathString  pathBase = val2.PathBase;
                _WebVirtualPath = pathBase.Value;
                if (string.IsNullOrWhiteSpace(_WebVirtualPath))
                {
                    _WebVirtualPath = "/";
                }
                string     scheme = val2.Scheme;
                HostString host   = val2.Host;
                string     value  = host.Value;
                pathBase     = val2.PathBase;
                _AbsoluteUrl = $"{scheme}://{value}{pathBase.Value}/";
            }
        }
Пример #2
0
        //==========
        #region auto log in
        public override void OnActionExecuting(ActionExecutingContext context)
        {
            var provider = ServiceCollectionExtension.Get <IActionDescriptorCollectionProvider>();
            var desc1    = (context.ActionDescriptor as ControllerActionDescriptor);
            var desc2    = provider.ActionDescriptors.Items.Cast <ControllerActionDescriptor>()
                           .Where(t => t.MethodInfo.GetCustomAttribute <ActionAttribute>() != null && t.DisplayName == desc1.DisplayName).FirstOrDefault();
            var desc3  = desc2 ?? desc1;
            var action = desc3.MethodInfo.GetCustomAttribute <ActionAttribute>();

            if (action != null)
            {
                var actions = ServiceCollectionExtension.Get <IPermissionService>();
                if (actions != null && !actions.HasPermission(context, desc3.Id))
                {
                    return;
                }
            }

            if (desc3.ActionName == "Index" && desc3.ControllerName == "Home")
            {
                if (User.Identity.IsAuthenticated)
                {
                    string path = HttpContext.Request.Query["from"];
                    if (string.IsNullOrEmpty(path))
                    {
                        path = CookieUtility.GetCookie(TbConstant.LAST_LOGIN_PATH);
                    }
                    if (!string.IsNullOrEmpty(path) && path != "/")
                    {
                        context.Result = Redirect(path);
                    }
                }
            }
            base.OnActionExecuting(context);
        }
Пример #3
0
        /// <summary>
        /// 程序启动将任务调度表里所有状态为 执行中 任务启动起来
        /// </summary>
        /// <param name="serviceCollection"></param>
        /// <returns></returns>
        public static IServiceCollection AddJobService(this IServiceCollection serviceCollection)
        {
            serviceCollection.BuildServiceProvider().RegisterServiceProvider();
            var jobCenter   = ServiceCollectionExtension.Get <IJobCenter>();
            var dbContext   = ServiceCollectionExtension.New <BaoDianContext>();
            var jobInfoList = dbContext.TaskSchedule
                              .Where(t => t.RunStatus.Equals((int)TaskJobStatus.DoJob))
                              .Select(t => new TaskScheduleModel
            {
                Id          = t.Id,
                JobGroup    = t.JobGroup,
                JobName     = t.JobName,
                CronExpress = t.CronExpress,
                StarRunTime = t.StarRunTime,
                EndRunTime  = t.EndRunTime,
                NextRunTime = t.NextRunTime,
                RunStatus   = t.RunStatus
            }).ToList();

            jobInfoList.ForEach(async t =>
            {
                await jobCenter.AddScheduleJobAsync(t);
            });
            return(serviceCollection);
        }
Пример #4
0
        static WebBase()
        {
            try
            {
                var actions = ServiceCollectionExtension.Get <IPermissionService>();

                if (actions != null)
                {
                    var provider       = ServiceCollectionExtension.Get <IActionDescriptorCollectionProvider>();
                    var descriptorList = provider.ActionDescriptors.Items.Cast <ControllerActionDescriptor>()
                                         .Where(t => t.MethodInfo.GetCustomAttribute <ActionAttribute>() != null).ToList();
                    actions.RegistAction(descriptorList);

                    actions.RegistRole();
                }
            }
            catch (Exception ex)
            {
                Log4Net.Error(ex);
            }
        }