When will I use my own RouteHandler?

I understand that in ASP.Net DynamicData (and possibly in 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 will populate this class? (provide sample code)

What would I do to do something useful?

What can I do with my own RouteProvider? Give examples where this would be useful.

As an example, I would like to make 401 redirects for some tables, but I will continue the default behavior for other tables (based on role or login, of course).

+3
source share
1 answer

SEO ( ) -. -, URL Rewriting . , URL-, , .

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

, slug (cheap-sumbrell-in-san-diego) ID (/blog/post.aspx?id=123465 )

+2

Source: https://habr.com/ru/post/1723507/


All Articles