public async Task Invoke(HttpContext context) { // TODO: Add support for caching. if (ShouldProcessImagePath(context.Request, out var imageResizeInfo)) { var imagePath = context.Request.Path; var imageFileInfo = _webHostEnvironment.WebRootFileProvider.GetFileInfo(imagePath); if (imageFileInfo.Exists) { var imageStream = imageFileInfo.CreateReadStream(); imageStream = await _imageProcessor.ProcessAsync(imageStream, imageResizeInfo); var imageContentType = WebPathHelper.GetMimeType(Path.GetExtension(imagePath)); context.Response.ContentType = imageContentType; context.Response.ContentLength = imageStream.Length; await context.Response.Body.WriteAsync(await imageStream.ReadAllBytesAsync(), 0, (int)imageStream.Length); return; } } await _next.Invoke(context); }
public async Task <IActionResult> SitemapIndexXml() { var sitemapList = new SitemapList(); sitemapList.Sitemaps.Add(Sitemap.CreateSitemap(Url.ContentLink(Url.Action(nameof(SitemapXml))))); var users = await _userService.GetQuery(new UserFilter { StoreSetup = true, StoreAccess = StoreAccess.Approved }) .Select(x => new { x.StoreSlug }) .ToListAsync(); sitemapList.Sitemaps.AddRange(from user in users select Sitemap.CreateSitemap(Url.ContentLink(Url.Action(nameof(SitemapXml), "Store", new { storeSlug = user.StoreSlug })))); return(File(Encoding.UTF8.GetBytes(sitemapList.ToXml()), WebPathHelper.GetMimeType(".xml"))); }
public IActionResult SitemapXml() { var sitemapUrlList = new SitemapUrlList { SitemapUrl.CreateUrl(Url.ContentLink(Url.Action(nameof(Index))), 1d), SitemapUrl.CreateUrl(Url.ContentLink(Url.Action(nameof(Pricing)))), SitemapUrl.CreateUrl(Url.ContentLink(Url.Action(nameof(Privacy)))), SitemapUrl.CreateUrl(Url.ContentLink(Url.Action(nameof(About)))), SitemapUrl.CreateUrl(Url.ContentLink(Url.Action(nameof(Contact)))), SitemapUrl.CreateUrl(Url.ContentLink(Url.Action(nameof(Terms)))) }; return(File(Encoding.UTF8.GetBytes(sitemapUrlList.ToXml()), WebPathHelper.GetMimeType(".xml"))); }
protected override Task PrepareAsync(Media media) { var fileExtension = Path.GetExtension(media.FileName).ToLowerInvariant(); var contentType = WebPathHelper.GetMimeType(fileExtension); var fileType = fileExtension.TrimStart('.').ToUpperInvariant(); var comparisonType = StringComparison.InvariantCultureIgnoreCase; media.ContentType = contentType; media.FileType = fileType; media.FileExtension = fileExtension; media.MediaType = _appSettings.ImageFileExtensions.Any(x => string.Equals(x, fileExtension, comparisonType)) ? MediaType.Image : _appSettings.AudioFileExtensions.Any(x => string.Equals(x, fileExtension, comparisonType)) ? MediaType.Audio : _appSettings.VideoFileExtensions.Any(x => string.Equals(x, fileExtension, comparisonType)) ? MediaType.Video : _appSettings.DocumentFileExtensions.Any(x => string.Equals(x, fileExtension, comparisonType)) ? MediaType.Document : throw new InvalidOperationException(); return(Task.CompletedTask); }
public async Task <IActionResult> SitemapXml() { var seller = await HttpContext.GetSellerAsync(); var sitemapList = new SitemapUrlList(); var products = await _productService.GetQuery().Where(x => x.SellerId == seller.Id && x.Published && !string.IsNullOrWhiteSpace(x.Slug)).Select(x => new { x.Slug }).ToListAsync(); var categories = await _categoryService.GetQuery().Where(x => x.SellerId == seller.Id && x.Published && !string.IsNullOrWhiteSpace(x.Slug)).Select(x => new { x.Slug }).ToListAsync(); sitemapList.Add(SitemapUrl.CreateUrl(Url.ContentLink(Url.Action(nameof(Index))))); sitemapList.AddRange(from product in products select SitemapUrl.CreateUrl(Url.ContentLink(Url.Action(nameof(Products), "Store", new { slug = product.Slug })))); sitemapList.AddRange(from category in categories select SitemapUrl.CreateUrl(Url.ContentLink(Url.Action(nameof(Products), "Store", new { slug = category.Slug })))); sitemapList.Add(SitemapUrl.CreateUrl(Url.ContentLink(Url.Action(nameof(Products))))); sitemapList.Add(SitemapUrl.CreateUrl(Url.ContentLink(Url.Action(nameof(About))))); sitemapList.Add(SitemapUrl.CreateUrl(Url.ContentLink(Url.Action(nameof(Contact))))); sitemapList.Add(SitemapUrl.CreateUrl(Url.ContentLink(Url.Action(nameof(Terms))))); sitemapList.Add(SitemapUrl.CreateUrl(Url.ContentLink(Url.Action(nameof(PrivacyPolicy))))); sitemapList.Add(SitemapUrl.CreateUrl(Url.ContentLink(Url.Action(nameof(ReturnPolicy))))); sitemapList.Add(SitemapUrl.CreateUrl(Url.ContentLink(Url.Action(nameof(ReviewPolicy))))); return(File(Encoding.UTF8.GetBytes(sitemapList.ToXml()), WebPathHelper.GetMimeType(".xml"))); }