Set a different homepage URL in ASP.NET CORE

In an ASP.NET Core project, I have the following route:

public class AboutController : Controller {

  [HttpGet("about-us")]
  public IActionResult Index() => View();

}

How to make this URL the default homepage of a site?

So when I go to www.mydomain.com, I automatically redirect to www.mydomain.com/about-us

Is this possible in ASP.NET Core or do I need to do this in a DNS domain?

+4
source share
3 answers

You can use below in your method Configure()(c Startup):

app.UseMvc(routes =>
{
    routes.MapRoute(
        name: "default",
        template: "{controller=About}/{action=about-us}/{id?}");
});

See also: Route Pattern Reference

+1
source

This is the way:

[HttpGet]
public IActionResult Get()
{
    return RedirectToAction("Index");
}

[HttpGet("about-us")]
public IActionResult Index() => View();
+1
source

URL Reweting Middleware:

var option = new RewriteOptions();
option.AddRedirect("^$", "about-us");

app.UseRewriter(option);
0

Source: https://habr.com/ru/post/1691132/


All Articles