I've been having trouble with changing the default route of my ASP.Net Core web app. I had changed the default route to other page but it still redirects me to the previous page. Below is the snippet of my code for reference:
Startup.cs
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseSession();
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapRazorPages();
endpoints.MapControllers();
});
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Main}"); //I had changed this but still redirect me Login
});
}
HomeController.cs
public class HomeController : Controller
{
public IActionResult Login()
{
return View();
}
[SessionTimeout]
public IActionResult Main()
{
return View();
}
}
As you can see, there are 2 actions in my controller. Previously I used Login as the default route. Now I want the default route to be Main. But it still redirects me to Login. I also had tried to change the launchUrl, but still doesn't solve this issue.
Really appreciates any help. Thanks in advance.