using System; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.DependencyInjection; using System.IO; using Vit.Extensions; using Vit.Core.Util.Common; namespace Vit.WebHost { public class RunArg { public Func OnCreateWebHostBuilder = () => new WebHostBuilder().UseKestrel(); /// /// 是否异步运行.Runs a web application and returns a Task that only completes when the token is triggered or shutdown is triggered. /// public bool RunAsync = false; #region wwwrootPath /// /// 静态文件路径。若不指定(null)则不映射静态文件 /// private string _wwwrootPath = null; /// /// 静态文件路径。可为相对路径或绝对路径。若为空字符串则默认为入口程序所在目录下的wwwroot文件夹。若不指定(null)则不映射静态文件。 /// public string wwwrootPath { get => _wwwrootPath; set { #region (x.1) get fullPath string fullPath = value; if ("" == fullPath) { fullPath = "wwwroot"; } if (fullPath != null) { fullPath = CommonHelp.GetAbsPath(fullPath); var dir = new DirectoryInfo(fullPath); if (dir.Exists) { fullPath = dir.FullName; } else { fullPath = null; } } #endregion _wwwrootPath = fullPath; } } #endregion /// /// 初始化 wwwroot静态文件配置的操作 /// public Action OnInitStaticFileOptions; public Action OnConfigureServices = null; public Action OnConfigure = null; public string[] urls; /// /// 允许跨域访问 /// public bool allowAnyOrigin = false; public RunArg SetPort(int port = 8888) { urls = new string[] { "http://*:" + port }; return this; } } }