public override async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next) { if (context?.Result is StatusCodeResult statusCodeResult && (statusCodeResult.StatusCode < 200 || statusCodeResult.StatusCode >= 300)) { await next.Invoke(); return; } var queryContainer = ContextProcessor.GetQueryContainer(context, _defaultPageSize, _defaultSort); if (queryContainer.ObjectResult == null) { await next.Invoke(); return; } if (_forcePagination || queryContainer.QueryOptions.QueryRequestsPagination) { queryContainer.ObjectResult.Value = await GetPaginationResult(queryContainer); } else { queryContainer.ObjectResult.Value = await queryContainer.Queryable.Cast <object>().ToListAsync(); } await next.Invoke(); }
public override async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next) { if (Configuration.AuditDisabled || IsActionIgnored(context.ActionDescriptor)) { await next.Invoke(); return; } var resultExecutionContext = await next.Invoke(); await AfterResultAsync(resultExecutionContext); }
public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next) { if (!(context.Result is ViewResult || context.Result is PageResult) || !(String.Equals("OrchardCore.Workflows", Convert.ToString(context.RouteData.Values["area"]), StringComparison.OrdinalIgnoreCase) && String.Equals("WorkflowType", Convert.ToString(context.RouteData.Values["controller"]), StringComparison.OrdinalIgnoreCase) && String.Equals("Edit", Convert.ToString(context.RouteData.Values["action"]), StringComparison.OrdinalIgnoreCase))) { await next.Invoke(); return; } dynamic layout = await _layoutAccessor.GetLayoutAsync(); var afterRegister = layout.Zones["WorkflowEditButtonsZone"]; afterRegister.Add(await _shapeFactory.New.AdditionalWorkflowEditorButtons()); await next.Invoke(); }
public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next) { // Should only run on the front-end for a full view if ((context.Result is ViewResult || context.Result is PageResult) && !AdminAttribute.IsApplied(context.HttpContext)) { if (_scriptsCache == null) { var settings = (await _siteService.GetSiteSettingsAsync()).As <CookiesSettings>(); //if (!string.IsNullOrWhiteSpace(settings?.ServicesScript)) //{ _scriptsCache = new HtmlString($"<script src=\"/TarteAuCitron.OrchardCore/Scripts/tarteaucitron.js\"></script>\n<script>tarteaucitron.init({{ \"privacyUrl\": \"{settings.PrivacyUrl}\", \"hashtag\": \"#tarteaucitron\", \"cookieName\": \"{settings.CookieName}\", \"orientation\": \"{settings.Orientation}\", \"showAlertSmall\": {settings.ShowAlertSmall.ToString().ToLower()}, \"cookieslist\": {settings.Cookieslist.ToString().ToLower()}, \"adblocker\": {settings.AdBlocker.ToString().ToLower()}, \"AcceptAllCta\" : {settings.AcceptAllCta.ToString().ToLower()}, \"highPrivacy\": {settings.HighPrivacy.ToString().ToLower()}, \"handleBrowserDNTRequest\": {settings.HandleBrowserDNTRequest.ToString().ToLower()}, \"removeCredit\": {settings.RemoveCredit.ToString().ToLower()}, \"moreInfoLink\": {settings.MoreInfoLink.ToString().ToLower()}, \"useExternalCss\": false, \"readmoreLink\": \"{settings.ReadMoreLink}\"}});</script>\n<script>{settings.ServicesScript}</script>"); //} } if (_scriptsCache != null) { //_resourceManager.RegisterLink(); _resourceManager.RegisterHeadScript(_scriptsCache); } } await next.Invoke(); }
public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next) { var siteSettings = await _siteService.GetSiteSettingsAsync(); var robotsSettings = siteSettings.As <RobotsTxtSettings>(); if (robotsSettings == null || !robotsSettings.NoIndex) { await next.Invoke(); return; } context.HttpContext.Response.Headers.Add("X-Robots-Tag", "noindex"); await next.Invoke(); }
public override async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next) { await next.Invoke(); var req = context.HttpContext.Request; var resp = context.HttpContext.Response; if (!ValidateMethod(req, resp)) { return; } if (CacheLocation != CacheLocation.Client) { var responseStream = resp.Body; responseStream.Position = 0; using (var streamReader = new StreamReader(responseStream, Encoding.UTF8, true, 512, true)) { var toCache = streamReader.ReadToEnd(); var contentType = resp.ContentType; await CacheService.Store($"{_cacheKey}{ContentType}", contentType, ServerSideDuration); await CacheService.Store(_cacheKey, toCache, ServerSideDuration); } } //if after method excecution and calculation of the eTag we recieve the same hastag we set up 304 status code if (req.Headers[HeaderNames.IfNoneMatch].Count != 0 && req.Headers[HeaderNames.IfNoneMatch] == context.HttpContext.Response.Headers[HeaderNames.ETag]) { context.HttpContext.Response.StatusCode = StatusCodes.Status304NotModified; // this will blank response } }
public override async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next) { var result = (PageResult)context.Result; result.ViewData["ipAddress"] = context.HttpContext.Connection.RemoteIpAddress.ToString(); await next.Invoke(); }
public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next) { var themeSettings = await GetThemeSettingsDetailAsync(); // Should only run on the front-end for a full view if (themeSettings != null && (context.Result is ViewResult || context.Result is PageResult) && !AdminAttribute.IsApplied(context.HttpContext)) { var cssVariables = new Dictionary <string, string>(); foreach (var field in themeSettings.FieldDefinitions.Where(x => _compatibleFields.Contains(x.FieldDefinition.Name))) { var value = GetFieldValue(themeSettings.Part, field); if (!string.IsNullOrWhiteSpace(value)) { cssVariables.Add(FormatName(field.Name), value); } } if (_stylesCache == null && cssVariables.Any()) { _stylesCache = new HtmlString($"<style>:root {{ {Environment.NewLine} {FormatCssVariables(cssVariables)} {Environment.NewLine} }}</style>"); } if (_stylesCache != null) { _resourceManager.RegisterStyle(_stylesCache); } } await next.Invoke(); }
public override async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next) { var Adres = context.HttpContext.Connection.RemoteIpAddress; var User = context.HttpContext.User.Identities; // var adresik = context.HttpContext.Connection.RemoteIpAddress.AddressFamily; var ff = System.Net.Dns.GetHostEntry(Adres).HostName; var IP_loop = System.Net.IPAddress.Loopback; var Adres_IP = System.Net.Dns.GetHostEntry(Adres).AddressList.First(x => x.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork); string dd = Adres_IP.ToString(); var result = context.Result; if (result is PageResult) { var page = ((PageResult)result); page.ViewData["filterMessage"] = $"Hej {ff} Adres IP: {dd}"; } await next.Invoke(); }
public override async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next) { var ipAddr = context.HttpContext.Connection.RemoteIpAddress.ToString(); var page = (PageResult)context.Result; page.ViewData["filterMessage"] = ipAddr; await next.Invoke(); }
public override async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next) { var ipAddress = context.HttpContext.Request.Host.ToString(); var result = (PageResult)context.Result; result.ViewData["IP"] = ipAddress; await next.Invoke(); }
public async override Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next) { var result = context.Result as ObjectResult; if (result == null || result.StatusCode < 200 || result.StatusCode >= 300) { await next.Invoke(); return; } var mapper = context.HttpContext.RequestServices.GetRequiredService <IMapper>(); result.Value = mapper.Map <IEnumerable <BookDto> >(result.Value); await next.Invoke(); }
public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next) { // should only run on the front-end for a full view if (!((context.Result is ViewResult || context.Result is PageResult) && !AdminAttribute.IsApplied(context.HttpContext))) { await next.Invoke(); return; } try { var pathBase = context.HttpContext.Request.PathBase; var siteSettings = await _siteService.GetSiteSettingsAsync(); var faviconSettings = siteSettings.As <ContentItem>("FaviconSettings")?.As <FaviconSettings>() ?? null; if (faviconSettings != null && faviconSettings.HasAppleTouchIcon) { _resourceManager.RegisterLink(new LinkEntry { Href = $"{pathBase}/icon.png", Rel = "apple-touch-icon" }); } if (faviconSettings != null && faviconSettings.HasFavicon) { _resourceManager.RegisterLink(new LinkEntry { Href = $"{pathBase}/favicon.ico", Rel = "shortcut icon" }); } if (faviconSettings != null && faviconSettings.HasWebAppManifest) { _resourceManager.RegisterLink(new LinkEntry { Href = $"{pathBase}/site.webmanifest", Rel = "manifest" }); } } catch (Exception ex) { _logger.LogError(ex, "Error defining meta/link tags for favicon feature"); } await next.Invoke(); }
public override async Task OnResultExecutionAsync(ResultExecutingContext result, ResultExecutionDelegate next) { var remoteIpAddress = result.HttpContext.Connection.Id; var page = ((PageResult)result.Result); page.ViewData["IPAddress"] = remoteIpAddress; // Do post work. await next.Invoke(); }
public override async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next) { var result = context.Result; if (result is PageResult) { var page = ((PageResult)result); page.ViewData["filterMessage"] = context.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString(); } await next.Invoke(); }
public async Task OnResultExecutionAsync(ResultExecutingContext filterContext, ResultExecutionDelegate next) { // Should only run on the front-end for a full view if ((filterContext.Result is ViewResult || filterContext.Result is PageResult) && !AdminAttribute.IsApplied(filterContext.HttpContext)) { //evaluate all rules provided var dynamicResources = await _dynamicResourcesService.GetDynamicResourcesAsync(); // string rule = "url('/my-user-home-page')"; if (dynamicResources.DynamicResources.Any()) { var engine = _scriptingManager.GetScriptingEngine("js"); var scope = engine.CreateScope(_scriptingManager.GlobalMethodProviders.SelectMany(x => x.GetMethods()), ShellScope.Services, null, null); foreach (var rule in dynamicResources.DynamicResources) { if (!string.IsNullOrEmpty(rule.Rule) && rule.Enabled) { var display = Convert.ToBoolean(engine.Evaluate(scope, rule.Rule)); if (display) { IEnumerable <string> rawTypes = rule.Resources .Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList(); if (rawTypes.Any()) { foreach (string resource in rawTypes) { dynamic layout = await _layoutAccessor.GetLayoutAsync(); // Render a mock widget so that its resources are included in the page var contentItem = await _contentManager.NewAsync(resource); // ("MessageRoom"); var shape = await _contentItemDisplayManager.BuildEditorAsync(contentItem, _modelUpdaterAccessor.ModelUpdater, true, "", Guid.NewGuid().ToString("n")); //This is a trick. //AdditionalResourcesDummyZone Zone does not need to be registered in layout //but this hack makes the zone shape render before the layout is executed , thus registering scripts and styles to thne style and script registries, to be executed later by layout //only if there was a @await RenderSectionAsync("AdditionalResourcesDummyZone", required: false) in layout would it be shown in view layout.Zones["AdditionalResourcesDummyZone"].Add(shape); } } } } } } } await next.Invoke(); }
public override async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next) { if (context.Result is PageResult result) { var user = await _userManager.GetUserAsync(context.HttpContext.User); result.ViewData["StatisicsIsEnabled"] = _featureToggleRepository.StatisicsIsEnabled(user); } await next.Invoke(); }
public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next) { await next.Invoke(); if (context.Result is FileStreamResult fileStreamResult && fileStreamResult.FileStream is FileStream fileStream) { string fileName = fileStream.Name; fileStream.Close(); await fileStream.DisposeAsync(); File.Delete(fileName); } }
/// <summary> /// Adds the current item to the stack /// </summary> /// <param name="filterContext"></param> public override async Task OnResultExecutionAsync(ResultExecutingContext filterContext, ResultExecutionDelegate next) { if (IgnoreAjaxRequests && isAjaxRequest(filterContext)) { await next.Invoke(); return; } if (ClearStack) { filterContext.HttpContext.ClearBreadCrumbs(); } var url = string.IsNullOrWhiteSpace(Url) ? filterContext.HttpContext.Request.GetEncodedUrl() : Url; if (UseDefaultRouteUrl) { url = getDefaultControllerActionUrl(filterContext); } if (UsePreviousUrl) { url = filterContext.HttpContext.Request.Headers["Referrer"]; } setEmptyTitleFromResources(); setEmptyTitleFromAttributes(filterContext); filterContext.HttpContext.AddBreadCrumb(new BreadCrumb { Url = url, Title = Title, Order = Order, GlyphIcon = GlyphIcon }); await next.Invoke(); }
public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next) { // Should only run on the front-end (or optionally also on the admin) for a full view. if ((context.Result is ViewResult || context.Result is PageResult) && (_options.AllowOnAdmin || !AdminAttribute.IsApplied(context.HttpContext))) { dynamic layout = await _layoutAccessor.GetLayoutAsync(); var footerZone = layout.Zones["Footer"]; footerZone.Add(await _shapeFactory.CreateAsync("MiniProfiler")); } await next.Invoke(); }
public override async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next) { var ipAddress = context.HttpContext.Request.Host.ToString(); var result = context.Result; if (result is PageResult) { var page = ((PageResult)result); page.ViewData["Twoje IP"] = ipAddress; } // var result = (PageResult)context.Result; //result.ViewData["Twoje IP"] = ipAddress; await next.Invoke(); }
public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next) { // Should only run on the front-end for a full view if ((context.Result is ViewResult || context.Result is PageResult) && !AdminAttribute.IsApplied(context.HttpContext)) { var settings = (await _siteService.GetSiteSettingsAsync()).As <GoogleAnalyticsSettings>(); if (!string.IsNullOrWhiteSpace(settings?.TrackingID)) { _resourceManager.RegisterHeadScript(new HtmlString($"<script async src=\"https://www.googletagmanager.com/gtag/js?id={settings.TrackingID}\"></script>")); _resourceManager.RegisterHeadScript(new HtmlString($"<script>window.dataLayer = window.dataLayer || [];function gtag() {{ dataLayer.push(arguments); }}gtag('js', new Date());gtag('config', '{settings.TrackingID}')</script>")); } } await next.Invoke(); }
public override async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next) { var result = context.Result; var addlist = Dns.GetHostEntry(Dns.GetHostName()); string GetHostName = addlist.HostName.ToString(); string GetIPV6 = addlist.AddressList[0].ToString(); string GetIPV4 = addlist.AddressList[1].ToString(); if (result is PageResult) { var page = ((PageResult)result); page.ViewData["filterMessage"] = GetIPV4; } await next.Invoke(); }
public Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next) { var correlationHeader = context.HttpContext.Request.Headers[Identifiers.CorrelationId]; //TODO:replace the following correlation id, since it's correlating all operation from this assembly instance. var correlationId = _operationalUnit.InstanceId; if (!string.IsNullOrEmpty(correlationHeader)) { Guid.TryParse(correlationHeader, out correlationId); } var messageHeader = new MessageHeader(isSucceed: context.HttpContext.Response.StatusCode == 200) { CorrelateId = correlationId }; var messageFooter = new MessageFooter { Sender = context.ActionDescriptor.DisplayName, Environemnt = _operationalUnit.Environment, Assembly = _operationalUnit.Assembly, FingerPrint = context.ActionDescriptor.Id, Route = context.RouteData.Values.ToDictionary(key => key.Key, value => value.Value?.ToString()), //TODO: infer the hint from HTTP status code Hint = ResponseHint.OK }; var rawContent = (context.Result as ContentResult)?.Content; context.Result = new ContentResult() { StatusCode = context.HttpContext.Response.StatusCode, ContentType = Identifiers.ApplicationJson, Content = JsonConvert.SerializeObject(closureGenerateResponseMessage(), Utilities.DefaultJsonSerializerSettings) }; _logger.LogInformation("Overriding response!"); return(next.Invoke()); object closureGenerateResponseMessage() { return(new { header = messageHeader, body = rawContent, footer = messageFooter }); } }
public override async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next) { var ip = context.HttpContext.Connection.RemoteIpAddress; ip = System.Net.Dns.GetHostEntry(ip).AddressList.First(x => x.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork); ip.ToString(); var result = context.Result; if (result is PageResult) { var page = ((PageResult)result); page.ViewData["filterMessage"] = $"Yours IP: {ip}"; } await next.Invoke(); }
public async override Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next) { var result = context.Result; if (result is PageResult) { var page = ((PageResult)result); var remoteIp = context.HttpContext.Connection.RemoteIpAddress; if (remoteIp.IsIPv4MappedToIPv6) { remoteIp = remoteIp.MapToIPv4(); } page.ViewData["filterMessage"] = remoteIp; } await next.Invoke(); }
public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next) { ObjectResult obj = context.Result as ObjectResult; if (obj != null) { var payload = new Model.Payload <object>() { Data = obj.Value, Message = new PayloadMessage() }; obj.Value = payload; } await next.Invoke(); }
public override async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next) { var queryContainer = ContextProcessor.GetQueryContainer(context, _defaultPageSize); if (queryContainer.ObjectResult == null) { return; } if (_forcePagination || queryContainer.QueryOptions.QueryRequestsPagination) { queryContainer.ObjectResult.Value = await GetPaginationResult(queryContainer); } else { queryContainer.ObjectResult.Value = await queryContainer.Queryable.Cast <object>().ToListAsync(); } await next.Invoke(); }
public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next) { if (context.Controller is Controller) { string appStyle = context.HttpContext.Session.Get <string>("AppStyle"); if (String.IsNullOrEmpty(appStyle)) { string userId = _userManager.GetUserId(context.HttpContext.User); AppUser user = await _userManager.FindByIdAsync(userId); appStyle = user.AppStyle ?? "flatly"; context.HttpContext.Session.Set <string>("AppStyle", appStyle); } ((Controller)context.Controller).ViewData["appStyle"] = appStyle; } await next.Invoke(); }
public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next) { // Should only run on the front-end for a full view if ((context.Result is ViewResult || context.Result is PageResult) && !AdminAttribute.IsApplied(context.HttpContext)) { var site = (await _siteService.GetSiteSettingsAsync()); var settings = site.As <FacebookSettings>(); if (!string.IsNullOrWhiteSpace(settings?.AppId)) { if (settings.FBInit) { var setting = _resourceManager.RegisterResource("script", "fb"); setting.AtLocation(ResourceLocation.Foot); } } } await next.Invoke(); }