Setting up

Installing it

To install Typed URL Routing, run the following command in the Package Manager Console for your project:

PM> Install-Package Dysphoria.Net.UrlRouting

Defining your routes

Create a class in your Controllers/ namespace called SiteUrls which inherits from Dysphoria.Net.UrlRouting.Urls, and add a static method void Register(RouteCollection):

namespace MyProjectNamespace.Controllers
{
    using System.Web.Routing;
    using Dysphoria.Net.UrlRouting;

    public class SiteUrls : Urls
    {
        internal static void Register(RouteCollection routes) 
        {
        }
    }
}

By default you’ll probably have a method in your Global class called RegisterRoutes. Add a line in RegisterRoutes to call your Register method:

private void RegisterRoutes(RouteCollection routes)
{
      // Existing line:
     routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

     SiteUrls.Register(routes); // <-- Add this line.
}

[If you don’t have a method in your Global class called RegisterRoutes, you will need to add some code to the Application_Start event to call SiteUrls.Register instead.]

Now you’re set up. You’ll add route definitions, and configure routes to call controller actions, in your SiteUrls class.

Continue to the main tutorial

Leave a Reply

Your email address will not be published. Required fields are marked *