301 Redirect dynamic urls from database in asp.net

☆樱花仙子☆ 提交于 2019-12-13 05:44:36

问题


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:


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.



来源:https://stackoverflow.com/questions/27119219/301-redirect-dynamic-urls-from-database-in-asp-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!