I have a login page which is outside Area and after successful login I want to redirect the user to a View inside Area.
I tried below code but it didn't work.
return RedirectToAction("Dashboard", "Home", new { Area = "StaffAug"});
return RedirectToAction("Dashboard", "StaffAug/Home");
it's redirecting to Home/Dashboard?area=StaffAug instead of StaffAug/Home/Dashboard
[Area("StaffAug")]
public class HomeController : Controller
{
private readonly ILogger<HomeController> _logger;
public HomeController(ILogger<HomeController> logger) { _logger = logger; }
public IActionResult Dashboard() { return View(); }
}
Be sure add area route to Startup.cs:
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "MyArea",
pattern: "{area:exists}/{controller=Home}/{action=Index}/{id?}");
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
});
Reference:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.