Реализовать аутентификацию.
И сделайте Dashboard контроллером по умолчанию. Волшебство случится, из коробки.
In Startup.cs
public void ConfigureServices(IServiceCollection services)
{
...
services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
.AddCookie("user_by_cookie", options =>
{
options.LoginPath = "/Login/Index/";
})
...
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
...
app.UseAuthentication();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Dashboard}/{action=Index}/{id?}");
});
...
}
Контроллер входа
[Authorize(AuthenticationSchemes = "user_by_cookie")]
public class LoginController : Controller
{
[HttpGet]
[AllowAnonymous]
public IActionResult Index()
{
return View();
}
[HttpPost]
[AllowAnonymous]
public IActionResult Index()
{
...
//authenticate();
...
return View();
}
[HttpGet]
public IActionResult Logout()
{
..
// logout(); ->
..
return RedirectToAction("Index");
}
}
в панели управления контроллера
[Authorize(AuthenticationSchemes = "user_by_cookie")]
public class DashboardController : Controller
{
[HttpGet]
public IActionResult Index()
{
return View();
}
}