28 public static ObjectResult
Created(
this ControllerBase controller,
object payload) => controller.StatusCode(HttpStatusCode.Created, payload);
53 => controller?.StatusCode((
int)statusCode, errorMessage) ??
throw new ArgumentNullException(nameof(controller));
63 public static VirtualFileResult?
TryServeFile(
this ControllerBase controller, IWebHostEnvironment hostEnvironment, ILogger logger,
string path)
65 ArgumentNullException.ThrowIfNull(controller);
66 ArgumentNullException.ThrowIfNull(hostEnvironment);
67 ArgumentNullException.ThrowIfNull(logger);
68 ArgumentNullException.ThrowIfNull(path);
70 var fileInfo = hostEnvironment.WebRootFileProvider.GetFileInfo(path);
73 logger.LogTrace(
"Serving static file \"{filename}\"...", path);
74 var contentTypeProvider =
new FileExtensionContentTypeProvider();
75 if (!contentTypeProvider.TryGetContentType(fileInfo.Name, out var contentType))
76 contentType = MediaTypeNames.Application.Octet;
77 else if (contentType == MediaTypeNames.Application.Json)
78 controller.Response.Headers.Add(
79 HeaderNames.CacheControl,
80 new StringValues(
new[] {
"public",
"max-age=31536000",
"immutable" }));
82 return controller.File(path, contentType);