ASP.NET 4.0 Web Form Routing

I have an existing site that I would like to convert to use routing, and after reading Scott Guthrie's post here , I built a working sample that works for most circumstances. However, since not all pages on an existing site match a specific template, I will need to check the database to determine which route (.aspx landing page) to use.

For example, most pages look like this:

http://www.mysite.com/people/person.html

This is good - I can easily redirect them to the view_person.aspx page because of the "people" directory.

But some pages look like this:

http://www.mysite.com/category_page.html http://www.mysite.com/product_page.html

This requires checking the database to see if you should go to the view_category.aspx page or the view_product.aspx page. And this is where I am stuck. Am I creating an IRouteHandler that checks the database and returns the route? Or is there a better way? The only code I found is suitable for answering this question .

Thanks in advance.

+3
source share
3 answers

, , , , ASPX-.

0

, :

http://www.mysite.com/pages/category_page.html

ASP.NET MVC , .

0

. .aspx script. , script, .

...

    private static void RegisterRoutes()
    {
        Route currRoute = new Route("{resource}.axd/{*pathInfo}", 
                                    new StopRoutingHandler());
        RouteTable.Routes.Add( "IgnoreHandlers", currRoute);

        currRoute = new Route("{urlname}",
                            new EPCRouteHandler("~/Default.aspx"));
        currRoute.Defaults = new RouteValueDictionary {{"urlname", "index.html"}};
        RouteTable.Routes.Add( "Default", currRoute);
    }

, ASP.Net 4.0, urlname script URL.

Now, how often the script answers check the database depends on how often the data in the database changes. You can easily cache paths and invalidate the cache when data is supposed to be changed, for example.

0
source

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


All Articles