URL routing with database search?

I want to create an ASP.NET MVC site so that the controller for a specific URL is stored in the database instead of the URL.

The reason for this is that I am building a CMS system, and users should be able to change the template (controller) without changing the URL. I also think that the controller name does not apply to end users, and I want a clean URL: s.

I understand that I could just add all the routes when the application starts, but for a system with about 100,000 pages this seems like a bad idea.

Is it possible to save url: s in the database and search for each request, and then map this request to a specific controller?

+3
source share
4

- :

- Global.asax.cs -

 routes.MapRoute(null,              // Route name
                 "content/{id}",    // URL with parameters               
                 new { Controller = "Content", Action = "Show", Id = (string) null });  // Parameter defaults

-/Controllers/ContentController.cs -

public class ContentController : Controller
{
    public ActionResult Show(string id)
    {
        // Lookup the 'content' (article, page, blog post, etc) in the repository (database, xml file, etc)
        ContentRepository repository = new ContentRepository();
        Content content = repository.FindContent(id);
        return View(content);
    }
}

www.yoursite.com/content/welcome-to-my-first-blog-post ContentController.Show( " -" ).

+1

, ASP.NET , PHP. , .

URL- 100K . , URL-, , . URL- .

-1

" 100 000 .

, , . {controller}/{action}/{id} . / ​​/ .

, , , .

, (ascx), . db , .

-1

Source: https://habr.com/ru/post/1709124/


All Articles