1

I am wanting to do customer routes for users where they get to pick their url name.

http://example.com/customer-name

Can I validate that the name they input isn't already registered in our routes? Like if someone typed "about", http://example.com/about, I could tell them that name is already in use because we have an About page.

Mike Flynn
  • 22,342
  • 54
  • 182
  • 341

2 Answers2

0

You should use a greedy route for the user defined routes. The route registration would look like:

routes.MapRoute("customCustomerRoute",
                "{*customerName}", 
                new { controller = "Customer", action = "Home" }
        );

and should go at the end of your routes, so that it doesn't get eat up other routes.

You can then have the customer name paths stored in a db, and look up that path before the user wants to create a new one.

You could get all possible existing routes with the following code:

var routes = new RouteCollection();
MvcApplication.RegisterRoutes(routes);

Then, you could see if those routes contain the url to be registered.

Oved D
  • 7,132
  • 10
  • 47
  • 69
0

I would place all the customer routes in a 'folder', ie. http://example.com/account/customer-name. No conflicts there.

Or place all other 'hardcoded' controllers in an area and prohibit this one for client use.

Jakub Konecki
  • 45,581
  • 7
  • 87
  • 126