I am using attribute based routing on my controller/action to define multiple URLs for the same action.
[Route("MyHome")]
[Route ("HomePage")]
[Route("Home")]
[Route("Home/admin")]
public ActionResult Index()
{
return View();
}
E.g. Above route defines different URLs for the Index action, http://mysite/home, http://mysite/myhome, http://mysite/homepage, http://mysite/home/admin.
It works fine if I defines routes at code time, but my requirement is that I want to store in database and then retrieve same from db and bind at application initialization; Does anyone has any idea how to do same? Thanks in advance.
RouteConfig.RegisterRoutes()like in previous versions of MVC? This method is called fromApplication_Start()in global.asax.Attributesare compiled as metadata into the assembly. By definition, you cannot edit attributes at runtime. If what you want to do is make a CMS that can be used to edit your routes at runtime, you will need to extend convention-based routing such as in this example.