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.

3
  • 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. Commented Oct 28, 2017 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. Commented Oct 28, 2017 at 17:18
  • I hope this reference can help anyone visit this topic! stackoverflow.com/questions/16026441/… Commented Jul 28, 2018 at 2:23

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.