脚本启动
1,发布至文件夹-例如:DemoPublic
2,管理员身份运行cmd
3,执行脚本
4,脚本参数格式:--参数名-参数值 例如:--desc="测试站点"
dotnet AspNetCore5Demo.dll --urls="http://localhost:99" --port="99" --desc="测试站点"
注意:在文件夹内执行脚本,dll根目录
代码
1,构造函数注入IConfiguration
private readonly ILogger<HomeController> _logger; private readonly IConfiguration _Configuration; public HomeController(ILogger<HomeController> logger, IConfiguration configuration ) { _logger = logger; _Configuration = configuration; }
2,根据参数名获取其参数值
public IActionResult Params()
{
base.ViewBag.port = _Configuration["port"];
base.ViewBag.desc = _Configuration["desc"];
return View();
}
3,Params.cshtml
<h1>脚本传值</h1> <div>port:<b>@ViewBag.port</b></div> <div>desc:<b>@ViewBag.desc</b></div>
显示效果