4

NET MVC 5** I want urls like this http://borntoprogram.com/.Net/.Net-Core/

I know i can achieve it using Attribute routing as shown below

[RoutePrefix(".Net")]
[Route("{action=Index}")]
public class NetController : Controller
{
    [Route(".Net-Core")]
    public ActionResult NetCore()
    {
        return View();
    }
}

but i want to Generate Controllers and Actions methods dynamically. And use Attribute routing with that.
I want to use Dots (.) in URL ,
second thing i want the urls to be very simple having just 3 parts like DomainName/CategoryOfArticle/ArticleName as in the URL DomainName -BornToProgram.com , CategoryofArticle -.Net , ArticleName -.Net-Core

IN all I WANT to allow admin to Decide parts of the URL For new articles that he can submit on monthly or daily basis. Like Category of Article (.Net in example) and Then Name of the Article( .Net-Core , .Net-Framework) The ADMIN want full control on the URLs

2
  • 2
    What do you mean generate controllers and actions methods dynamically? Commented Feb 5, 2016 at 0:39
  • 1
    as asked in this question stackoverflow.com/questions/3303801/… Commented Feb 5, 2016 at 0:47

1 Answer 1

2

Since attributes are used to attach metadata to a class, it is not possible to dynamically add them at runtime. But even if you could, it is unlikely the Attribute Routing framework that reads and converts them into Route instances would function correctly.

If you need to make dynamically driven routes, the solution is to inherit RouteBase so you can add URLs and/or specify which controller they should refer to at runtime. You should cache the URL list as in the example, but there is no reason why you couldn't adapt the cache so individual URLs could be added to it one by one when they are added in your application (add them to the cache and the data source in one go, so they are both immediately and permanently available).

Sign up to request clarification or add additional context in comments.

Comments

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.