public IActionResult WebManifest([FromServices] WebManifest wm) { if (wm == null) { return(NotFound()); } Response.ContentType = "application/manifest+json; charset=utf-8"; // Cache for 30 days as prescribed by https://www.w3.org/TR/appmanifest/#obtaining Response.Headers[HeaderNames.CacheControl] = $"max-age={60 * 60 * 24 * 30}"; return(Content(wm.RawJson)); }
public IActionResult WebManifest([FromServices] WebManifest wm) { if (wm == null) { return(NotFound()); } Response.ContentType = "application/manifest+json; charset=utf-8"; Response.Headers[HeaderNames.CacheControl] = $"max-age={_options.WebManifestCacheControlMaxAge}"; return(Content(wm.RawJson)); }
public WebManifest GetManifest() { return(_cache.GetOrCreate("webmanifest", (entry) => { IFileInfo file = _env.WebRootFileProvider.GetFileInfo(_fileName); entry.AddExpirationToken(_env.WebRootFileProvider.Watch(_fileName)); string json = File.ReadAllText(file.PhysicalPath); WebManifest manifest = JsonConvert.DeserializeObject <WebManifest>(json); manifest.FileName = _fileName; manifest.RawJson = Regex.Replace(json, "(\"(?:[^\"\\\\]|\\\\.)*\")|\\s+", "$1"); if (!manifest.IsValid(out string error)) { throw new JsonException(error); } return manifest; }));