应用集群测试及nginx,redis应用(一)
创建一个.net core web项目
FirstController内容:
public class FirstController : Controller { private readonly ILogger<FirstController> _logger; private readonly IConfiguration _config; private static int _TotalCOunt = 0; public FirstController(ILogger<FirstController> logger, IConfiguration config) { _logger = logger; _config = config; } public IActionResult Index() { _logger.LogWarning($"这是FirstControolerIndex请求端口:{this._config["port"]}"); #region 地址信息 ViewBag.BrowserUrl = $"{Request.Scheme}://{Request.Host.Host}:{_config["port"]}/"; ViewBag.TotalCount = _TotalCOunt++; #endregion #region Session var user = HttpContext.Session.GetString("CurrentUser"); if (string.IsNullOrEmpty(user)) { HttpContext.Session.SetString("CurrentUser", $"测试-{_config["port"]}-{_TotalCOunt}"); _logger.LogWarning($"这是HomeController{_config["port"]} Session"); } ViewBag.SessionUser = HttpContext.Session.GetString("CurrentUser"); #endregion return View(); } }
Index视图内容:
应用集群测试
地址:@ViewBag.BrowserUrl
请求响应次数:@ViewBag.TotalCount
当前用户: @ViewBag.SessionUser
找到项目对应的文件夹
输入以下命令启动三个应用程序:
dotnet test.dll --urls="http://*:5555" --ip="127.0.0.1" --port=5555 dotnet test.dll --urls="http://*:7777" --ip="127.0.0.1" --port=7777 dotnet test.dll --urls="http://*:8888" --ip="127.0.0.1" --port=8888
全部启动后画面:
好好学习,天天向上。