如何在ASP.NET中管理批量重定向 [英] How to manage bulk redirects in ASP.NET

查看:64
本文介绍了如何在ASP.NET中管理批量重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想管理301,404和其他重定向。我可以在sql server数据库中创建一个表(它将包含旧的和新的url)。当有人点击旧网址时,如何在前端服务器中调用它们。



非MVC首选解决方案。应该很快。



我感谢任何帮助。谢谢。



我尝试了什么:



我试过用它手动,但目前这么多的URL是不可行的。

I want to manage 301,404 and other redirects. I can create a table in the sql server database (which will contain the old and new url). How to call them in the front end server when anyone hits the old URL.

Solution for non-MVC preferred. Should be fast.

I appreciate any help. Thanks.

What I have tried:

I tried using it manually but it's not feasible at the moment with so many URLs.

推荐答案

有很多方法可以处理重定向。这些订单的顺序对于创建了多少应用程序开销(如果有的话)是显着的;开销越少,网站的性能就越高。



1.在(网络)服务器级别。这通常通过 .htaccess 文件完成,或者在ASP.NET站点中可以通过 web.config 文件完成。这种方法的优点是对应用程序几乎没有任何影响,因此您将看到接近0的性能影响。这种方法的缺点是它是通过应用程序的配置文件完成的,通常需要重新启动应用程序。



2.在http管道中。这将通过一个模块(aka hook,handler)。这可以写成拦截每个请求,并确定我们是否应该让它去网站或我们是否需要做其他事情;例如重定向,返回404等。优势在于它仍处于早期阶段并且对性能影响很小,并且非常强大。这样做的缺点是它是有效实施的最难的方法。这是一个非常强大的选项,可能会因为一个简单的错误而导致您的网站崩溃。



3.服务器端文件。每个文件都有一个程序化重定向。维护非常繁琐。您也可以在MVC控制器中使用它。运行此应用程序需要整个应用程序。



4.客户端文件。每个html文件都有一个< meta refresh>元素在里面。与服务器端变体相同的弱点,它需要浏览器实际处理以及< meta refresh>的事实。可能不支持或禁用。



如何使用数据库。您可以使用DB实现所有4种方法。您选择实施重定向解决方案的方法将决定如何集成数据库。如果您使用的是配置/ htaccess文件,则需要根据数据库表重写重定向块。



我个人使用方法2,因为我需要在基于MVC的CMS中出于安全目的开发iHttpHandler。我将所有重定向加载到一个集合中,并扫描每个请求。早期的版本在每次调用时都访问了数据库,但这会产生我需要摆脱的开销。
There are a multitude of ways that redirects can be handled. The order that these are in is signifigant in the fact of how much application overhead is created, if any; the less overhead that is onvolved the more performance your website will have.

1. At the (web) server level. This would be normally done via an .htaccess file or in ASP.NET sites could be via the web.config file. The advantage with this method is that there is little if any impact on the application so you will see near 0 performance impact. The disadvantage to this method is that it is done via the configuration file for the application and generally requires an application restart.

2. Within the http pipeline. This would be via a module (aka hook, handler). This can be written to intercept every request, and determine if we should let it go to the website or if we need to do something else; such as a redirect, return a 404, etc. The advantage is that this is still early in the pipeline and has little performance impact, and is very powerful. The disadvantage to this is that it is the hardest method to effectively implement. This is a very powerful option and can crash your site with a simple error.

3. Server side file. Every file has a programmatic redirect located within it. Very tedious to maintain. You could also use this within an MVC controller. The entire application is needed to run this.

4. Client side file. Every html file has a <meta refresh> element in it. Same disadvantagse as the server side variant, and it requires the browser to actually process- along with the fact that <meta refresh> may not be supported or disabled.

How to with a DB. You could implement all 4 methods utilizing a DB. The method you choose to implement your redirect solution will dictate how to integrate the DB. If you are using a configuration/htaccess file you would need to rewrite the block of redirects based on your DB table.

I personally use method 2, as I needed to develop an iHttpHandler for security purposes in an MVC based CMS. I load up all of the redirects into a collection and scan that for every request. Earlier versions accessed the DB on every call but this created overhead which I needed to get rid of.


使用数据库来管理它是 - 嗯 - 愚蠢。谷歌将提供丰富的替代品,例如这个。



如何自动将浏览器重定向到另一个网页 [ ^ ]
Using a database to manage this is - well - stupid. Google will provide a wealth of alternatives, such as this one.

How to automatically redirect a browser to another web page from one of your own[^]


您可以在网络中指定自定义301和404错误页面.config,并在该页面的代码后面(在 PageLoad 方法?)中,评估404响应,其中应包括错误的URL,并编写代码以重定向到适当的页面。



所以,如果坏网址是 http://www.example.com/hello11​​1 ,您可以将字符串设置为正确的URL( http://www.example.com/hello-world )。
You could specify a custom 301 and 404 error page in the web.config, and in the code behind for that page (in the PageLoad method?), evaluate the 404 response, which should include the faulty url, and write code to redirect to the appropriate page.

So, if the bad url was http://www.example.com/hello111, you could set a string to the correct url (http://www.example.com/hello-world).


这篇关于如何在ASP.NET中管理批量重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆