Hi I use the mapRoutes in ASP.Net Core I can set the default controller route. When starting the application the entry point will be the default Home but all that will be shown is https://localhost:43594 rather than showing the /Home on the end.
Is there a way to explicitly enforce this?
There are several workarounds:
For changing Route URL, you could try URL Rewriting Middleware or Custom Middleware.
Here are available options in Startup:
Rewrite URL
app.UseRewriter(new RewriteOptions().AddRewrite("/","/Home",true));
Redirect URL
app.UseRewriter(new RewriteOptions().AddRedirect("/", "/Home"));
Custom Middleware
app.Use(async (context, next) =>
{
if (context.Request.Path == "/")
{
context.Response.Redirect("Home/", true);
return;
}
await next();
});
Use the above options before app.UseMvc
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With