301 Redirect dynamic urls from database in asp.net

2019-08-18 06:31发布

I have thousands of links which need to be redirect to new URL using 301 Permanent Redirect. I have all these urls in the Database table. I would like to know where should be these URLs should be loaded (only once). And can be used for 301 permanent redirect.

Sample URLs:

*RequestForURL*                                                             *301Redirect*


why-me/onboard-experience/food-and-drink-for-all-tastes/family-casual/->    /why-me/family-test/
    why-me/onboard-experience/food-and-drink-for-all-tastes/room-service/-> /why-me/onboard-experience/food-for-all-tastes/
    why-me/onboard-experience/food-and-drink-for-all-tastes/specialist-restaurants/->   /why-me/onboard-experience/food-for-all-tastes/
    why-me/onboard-experience/food-for-all-tastes/me-deals/->   /why-me/onboard-experience/
    why-me/onboard-experience/food-for-all-tastes/me-deals/wowsale2013.aspx /why-me/onboard-experience/
    why-me/onboard-experience/food-for-all-tastes/dining-packages/->    /why-me/onboard-experience/food-for-all-tastes/
    why-me/onboard-experience/food-for-all-tastes/drinks-packages/->    /why-me/onboard-experience/dazzling-entertainment/drink-packages/
    why-me/onboard-experience/food-for-all-tastes/family-casual/->  /why-me/onboard-experience/food-for-all-tastes/
    why-me/onboard-experience/food-for-all-tastes/room-service/ /why-me/onboard-experience/food-for-all-tastes/
    why-me/onboard-experience/food-for-all-tastes/speciality-dining/->  /why-me/onboard-experience/food-for-all-tastes/
    why-me/onboard-experience/types-of-me/->    /why-me/onboard-experience/

I am using VS 2013 Framework 4.0

NOTE: Data must be loaded once only into Session or during first application request.

1条回答
太酷不给撩
2楼-- · 2019-08-18 07:11

Load the values from the database in Application_Start into a static Dictionary<string, string>, then check the requested URL in BeginRequest to see if it's key exists in a redirect dictionary, then do context.Response.RedirectPermanent(value) if it does.

查看更多
登录 后发表回答