Beispiel #1
0
 public void Configure(IApplicationBuilder app, IHostingEnvironment env)
 {
     if (HostingEnvironmentExtensions.IsDevelopment(env))
     {
         DeveloperExceptionPageExtensions.UseDeveloperExceptionPage(app);
     }
     else
     {
         ExceptionHandlerExtensions.UseExceptionHandler(app, "/Error");
         HstsBuilderExtensions.UseHsts(app);
     }
     HttpsPolicyBuilderExtensions.UseHttpsRedirection(app);
     StaticFileExtensions.UseStaticFiles(app);
     MvcApplicationBuilderExtensions.UseMvc(app);
 }
Beispiel #2
0
        public async Task Invoke(HttpContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            using (StopWatchTimer stopwatchTimer = StopWatchTimer.Initialise(_timings))
            {
                string fileExtension = RouteFileExtension(context);

                if (!String.IsNullOrEmpty(fileExtension) &&
                    StaticFileExtensions.Contains($"{fileExtension};"))
                {
                    await _next(context);

                    return;
                }

                string route = RouteLowered(context);

                if (route.Length > 1 && route[route.Length - 1] == Constants.ForwardSlashChar)
                {
                    route = route.Substring(0, route.Length - 1);
                }

                string    cacheName = $"Seo Cache {route}";
                CacheItem cacheItem = _memoryCache.GetCache().Get(cacheName);

                if (cacheItem == null)
                {
                    _seoProvider.GetSeoDataForRoute(route, out string title, out string description,
                                                    out string author, out List <string> tags);
                    cacheItem = new CacheItem(cacheName, new SeoCacheItem(title, description, author, tags));
                    _memoryCache.GetCache().Add(cacheName, cacheItem);
                }

                SeoCacheItem seoCache = (SeoCacheItem)cacheItem.Value;
                context.Items[SeoMetaAuthor]      = seoCache.Author;
                context.Items[SeoTitle]           = seoCache.Title;
                context.Items[SeoMetaDescription] = seoCache.Description;
                context.Items[SeoMetaKeywords]    = seoCache.Keywords;
            }

            await _next(context);
        }