0

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.

Ashish Shukla
  • 1,239
  • 12
  • 23
  • Have you tried getting those urls from DB and assigning in `RouteConfig.RegisterRoutes()` like in previous versions of MVC? This method is called from `Application_Start()` in global.asax. – derloopkat Oct 28 '17 at 11:54
  • 2
    `Attributes` are 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](https://stackoverflow.com/a/31958586/181087). – NightOwl888 Oct 28 '17 at 17:18
  • I hope this reference can help anyone visit this topic! https://stackoverflow.com/questions/16026441/dynamic-routes-from-database-for-asp-net-mvc-cms – Thong Vo Jul 28 '18 at 02:23

0 Answers0