views:

118

answers:

1

I understand that in ASP.Net DynamicData (and maybe regular ASP or MVC) I can provide my own RouteHandler

routes.Add(new DynamicDataRoute("{table}/{action}.aspx") {
    RouteHandler = new CustomRouteHandler() 
});

public class CustomRouteHandler : DynamicDataRouteHandler
{
    public override IHttpHandler CreateHandler(DynamicDataRoute route, MetaTable table, string action)
    {
        // what kind of cool stuff should I add in here?
        return base.CreateHandler(route, table, action);
    }

    protected override string GetCustomPageVirtualPath(MetaTable table, string viewName)
    {
        // what kind of cool stuff should I add in here?
        return base.GetCustomPageVirtualPath(table, viewName);
    }

    protected override string GetScaffoldPageVirtualPath(MetaTable table, string viewName)
    {
        // what kind of cool stuff should I add in here?
        return base.GetScaffoldPageVirtualPath(table, viewName);
    }
}

But can someone explain how I would fill this class out? (give some example code)

What would I override to do something useful?

What sort of things could I do with my own RouteProvider? Give me examples where this would be useful.

As an example, I would like to do a 401 redirect for some tables but continue with the default behavior for other tables (based upon role or logged-in user, of course).

+2  A: 

You could use it for SEO (search engine optimization) in any number of web applications. Something that could have been accomplished with URL Rewriting in the past. For instance, if you were to build a blog engine, and wanted to have a slug in the url that included keywords for your article, you could add this as a handler.

http://mysite.com/blog/cheap-umbrellas-in-san-diego.aspx

You can then create a route handler to deal with that particular pattern and look up your post by slug (cheap-umbrellas-in-san-diego) vs by something like ID (/blog/post.aspx?id=123465)

Sean
Thanks. Have you done anything like this? Can you show some example code?
Jason M
Have a read through this: http://chriscavanagh.wordpress.com/2008/03/11/aspnet-routing-goodbye-url-rewriting/
Sean
And this as well: http://msdn.microsoft.com/en-us/magazine/dd347546.aspx
Sean