public override void OnActionExecuting(ActionExecutingContext context) { var provider = ServiceExtension.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 = ServiceExtension.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 = CookieUtil.GetCookie(Constants.LAST_LOGIN_PATH); } if (!string.IsNullOrEmpty(path) && path != "/") { context.Result = Redirect(path); } } } base.OnActionExecuting(context); }
protected PathUtil() { IHostingEnvironment val = ServiceExtension.Get <IHostingEnvironment>(); _HostingEnvironment = val; _WebPhysicalPath = val.WebRootPath; _ContentPhysicalPath = val.ContentRootPath; if (ServiceExtension.HttpContext == null) { _WebVirtualPath = "/"; _AbsoluteUrl = "/"; } else { HttpRequest val2 = ServiceExtension.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}/"; } }
static WebBaseController() { try { var actions = ServiceExtension.Get <IPermissionService>(); if (actions != null) { var provider = ServiceExtension.Get <IActionDescriptorCollectionProvider>(); var descriptorList = provider.ActionDescriptors.Items.Cast <ControllerActionDescriptor>() .Where(t => t.MethodInfo.GetCustomAttribute <ActionAttribute>() != null).ToList(); actions.RegistAction(descriptorList); actions.RegistRole(); } } catch (System.Exception ex) { LogUtil <WebBaseController> .Error(ex.Message); } }