Answer the question
In order to leave comments, you need to log in
How to make friendly urls correctly?
I want to make a convenient link instead of the standard url of the site.ru/Home/Info/Page type, in which there will be no controller and action, i.e. to get it like this site.ru/page. I googled the HttpGet attribute and it seems to work with it, but the problem is that sudden variables like favicon.ico arrive in this action and cause an error. Therefore, I'm wondering if there is a more correct method for creating friendly links?
public class HomeController : Controller
{
private readonly DataManager dataManager;
public HomeController(DataManager dataManager)
{
this.dataManager = dataManager;
}
[HttpGet("{id}", Name = "Info")]
public IActionResult Info(string id)
{
var page = dataManager.Pages.GetPageByUrl(id);
return View(page);
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question