StaticFilesConfig.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. using System;
  2. using Microsoft.AspNetCore.Builder;
  3. using Vit.Core.Util.Common;
  4. using Newtonsoft.Json;
  5. using System.Collections.Generic;
  6. using Microsoft.AspNetCore.StaticFiles;
  7. namespace Vit.WebHost
  8. {
  9. #region StaticFiles
  10. [JsonObject(MemberSerialization.OptIn)]
  11. public class StaticFilesConfig
  12. {
  13. /// <summary>
  14. /// 请求路径(可不指定)。demo:"/file/static"。The relative request path that maps to static resources
  15. /// </summary>
  16. [JsonProperty]
  17. public string requestPath { get; set; }
  18. #region rootPath
  19. private string _rootPath = null;
  20. /// <summary>
  21. /// 静态文件路径。可为相对路径或绝对路径。若为空或空字符串则为默认路径(wwwroot)。demo:"wwwroot"
  22. /// </summary>
  23. [JsonProperty]
  24. public string rootPath
  25. {
  26. get => _rootPath;
  27. set
  28. {
  29. if (string.IsNullOrEmpty(value))
  30. {
  31. _rootPath = null;
  32. return;
  33. }
  34. else
  35. {
  36. _rootPath = CommonHelp.GetAbsPath(value);
  37. }
  38. }
  39. }
  40. #endregion
  41. /// <summary>
  42. /// 默认页面(可不指定)。An ordered list of file names to select by default. List length and ordering may affect performance
  43. /// </summary>
  44. [JsonProperty]
  45. public List<string> defaultFileNames { get; set; }
  46. /// <summary>
  47. /// 是否可浏览目录(default false)。Enables directory browsing
  48. /// </summary>
  49. [JsonProperty]
  50. public bool? useDirectoryBrowser { get; set; }
  51. /// <summary>
  52. /// 回应静态文件时额外添加的http回应头。可不指定。
  53. /// </summary>
  54. [JsonProperty]
  55. public IDictionary<string, string> responseHeaders { get; set; }
  56. #region contentTypeProvider
  57. [JsonIgnore]
  58. public IContentTypeProvider contentTypeProvider { get; set; }
  59. /// <summary>
  60. /// 静态文件类型映射配置的文件路径。可为相对路径或绝对路径。例如"contentTypeMap.json"。若不指定(或指定的文件不存在)则不指定文件类型映射配置
  61. /// </summary>
  62. [JsonProperty]
  63. public string contentTypeMapFile
  64. {
  65. set
  66. {
  67. contentTypeProvider = WebHostHelp.BuildContentTypeProvider(value);
  68. }
  69. }
  70. #endregion
  71. /// <summary>
  72. /// 初始化 wwwroot静态文件配置的操作
  73. /// </summary>
  74. public Action<StaticFileOptions> OnInitStaticFileOptions { get; set; }
  75. }
  76. #endregion
  77. }