URL Routing for Database Driven URLs in ASP.NET MVC Websites

By: Jignasha
Updated: June 19th, 2019 | Technology: Asp.Net, Asp.Net MVC, SEO Friendly
URL Routing for Database Driven URLs in ASP.NET MVC Websites

Introduction:

This Article is for the setting up database driven URL routing for ASP.NET MVC website development. Here we are going to learn that, how to customize the ASP.NET MVC website by URL routing and route variable URL paths to a controller and action of our choice. Mainly the URL routing is most important for making SEO friendly ASP.NET MVC websites.

Why We Need Custom URL Routing in ASP.NET MVC:

Nowadays in technology, everybody wants to access the site as www.youdomain.com/a1, www.yourdomain.com/a2, etc. with a1, a2. mainly this type of URLs is used to make a decision for search engines when it is crawling for a particular keyword. this way we can set custom URLs in ASP.NET MVC website. so that we can make a successful SEO Friendly website by making a little c# code in ASP.NET MVC.

Let’s discuss and set up how to make custom URL routing for making SEO friendly ASP.NET MVC website.

URL routing with ASP.NET MVC, I had a problem because default URL routing is handled by only asp.net controller/actions.

Don’t worry about that, We have another easy way of controlling the URL routing. here is we have own custom routing and overriding  IRouteConstraint interface.

Follow the step by step guideline for setup URL routing in ASP.NET MVC website. suppose we need company based on extensionless URLs.

Let’s Start! I have one table with a name like “Companies”.

url routing in asp.net mvc websites

Here is ready-made SQL code for the table.

Now, just create an Asp.Net web application into solution.

Suppose, I would like to create a dynamic routing example to my solution with any name. kindly follow below nine steps for the solution.

  1. Add Web Application in your Solution.
  2. Add Data access in Solution And.Dbml or else .edmx.
  3. Add your Table in .dbml or .edmx file.
  4. Add Interface IRepository.cs in your, DataAccess look like.

  1. Implement your Interface method into Repository class add a new file in Data access with the name “Repository.cs”.

  1. Add Company Controller in your MVC web application Project and Index Action like.

  1. Add View Company Index Action (design view as per your requirement).
  2. Open your Routeconfig.cs file in your web application project and modify RouteConfig.cs file like below.

  1. Open your Global.asax file and RegisterRoutes in Application_Start events like below.

I hope this above solution will be helpful for you and if you would like any support for a related article you can just a comment on a blog.

I have also uploaded the same dynamic URL routing example in ASP.NET MVC application, You can directly download the URL routing example on below Github link.

https://github.com/prajapatichintan/database-driven-urls-for-asp-net-mvc-website

You may also like my other interesting articles for ASP.NET MVC.