I am just beginning by helping cover their C# and ASP.Internet and also have the following questions. I'm dealing with code modified from the couple different lessons having fun with Northwind and also have become this far. Their email list of acceptable groups is presently hard created in a string but I must lookup the CategoryName within the database to ensure it is available.

Clearly the objective of this really is to make sure that customers don't just type:
world wide web.domain.com/Groups/AnyUrlWillWork and return a legitimate page.

Also does anybody come with an tips of methods they coping capital issues because the routing is situation sensitive? For instance Groups/drinks should toward Groups/Drinks ?

Thanks ahead of time for just about any assistance, and glad to become joining Stack Overflow.

//Complex contraint class
public class EchoConstraint : IRouteConstraint
{
    public readonly string[] ValidMessages = { "Beverages", "Produce", "Confections", "Seafood" };

    public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
    {
        string message = values["CategoryName"] as string;
        return ValidMessages.Contains(message);
    }
}


//Routes
RouteTable.Routes.MapPageRoute(
                        "Category Route",                       // Route name
                        "Categories/{CategoryName}",            // Url pattern
                        "~/ShowProductsInCategory.aspx",        // Physical file
                        true,
                        new RouteValueDictionary            
                            {{"CategoryName", "Beverages"}},         //Sets default value if none is provided in URL
                        new RouteValueDictionary 
                            {{"CategoryName", new EchoConstraint()}}
                           );

Is MVC? If that's the case, why don't you path to a function, that will look into the category title against your computer data store and redirect for an error page if such category does not exist?

public ActionResult Index(string catName)
{
    if (string.IsNullOrEmpty(catName) || !MyCategoriesDataStore.Exists(catName))
        return RedirectToAction("CategoryError");

    // Load category data to be used from View

    return View();
}

A WebForms solution could be:

    public class EchoConstraint : IRouteConstraint
    {
        private IRepository rep;
        public EchoConstraint(IRepository r) { rep = r; }

        public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
        {
            return rep.GetCategory(message) == 0;
        }
    }
.
.
.
                        new RouteValueDictionary 
                            {{"CategoryName", new EchoConstraint(myDataAccessRepo)}}
                           );

In which you pass an item of sophistication applying IRepository together with your data access logic (using NHibernate, EntityFramework or perhaps your own DAL implementation). You have to return a bool value, which is things i did.