I have an ASP MVC3 website with a rest API service. When a user passes in an invalid API or they have been blacklisted i wish to ignore the response. I know I could send back a 404 or pass back an 503 but if someone keeps polling me then I would ideally like to ignore the response causing a time-out their end. Thus delaying the hammering my server gets.
我有一个ASP MVC3网站和一个rest API服务。当用户传入无效的API或被列入黑名单时,我希望忽略响应。我知道我可以发送404或503,但如果有人一直轮询我,那么我最好忽略响应,导致他们超时。这样就延迟了服务器的锤击。
Is this possible within ASP.net MVC3? If so any help would be most appreciated. Thank you
这在ASP.net MVC3中可行吗?如有任何帮助,我们将不胜感激。谢谢你!
1 个解决方案
#1
1
For what you want, you still need to parse the request, so it will always consume server resources, specially if you have an annoying user sending a query every 500ms...
对于您想要的,您仍然需要解析请求,因此它将始终消耗服务器资源,特别是如果您有一个烦人的用户每500ms发送一个查询……
In this situations you would block the IP / Header of the request for a period of, for example 10 minutes, but it would be a very good idea to block it on your load balancer and prevent that request that even reach your application, this is easily accomplish if you're using Amazon Services to run your Service, but all other cloud provider do support this as well, if by any means you are using a cloud hosting.
在这种情况下,您将阻止请求的IP /头一段,例如10分钟,但这将是一个很好的想法阻止它在你的负载均衡器,防止该请求,即使达到您的应用程序,这很容易做到,如果你使用亚马逊服务运行服务,但所有其他云提供商做支持,如果以任何方式使用云托管。
if you can only use your web application, and this is a solution that is not tested, you could add an ignored route to your routing mechanism like:
如果您只能使用web应用程序,而这是一个没有经过测试的解决方案,您可以添加一条被忽略的路由到您的路由机制,比如:
routes.IgnoreRoute("{*allignore}", new {allignore=@".*\.ignore(/.*)?"});
and upon check that the IP is banned, simple redirect using for example Response.Redirect()
to your site, to a .ignore
path... or, why not redirecting that request to google.com
just for the fun of it?
在检查IP被禁止后,使用简单的重定向,例如Response.Redirect()到您的站点,到。ignore path…或者,为什么不把这个请求重定向到google。com呢?
#1
1
For what you want, you still need to parse the request, so it will always consume server resources, specially if you have an annoying user sending a query every 500ms...
对于您想要的,您仍然需要解析请求,因此它将始终消耗服务器资源,特别是如果您有一个烦人的用户每500ms发送一个查询……
In this situations you would block the IP / Header of the request for a period of, for example 10 minutes, but it would be a very good idea to block it on your load balancer and prevent that request that even reach your application, this is easily accomplish if you're using Amazon Services to run your Service, but all other cloud provider do support this as well, if by any means you are using a cloud hosting.
在这种情况下,您将阻止请求的IP /头一段,例如10分钟,但这将是一个很好的想法阻止它在你的负载均衡器,防止该请求,即使达到您的应用程序,这很容易做到,如果你使用亚马逊服务运行服务,但所有其他云提供商做支持,如果以任何方式使用云托管。
if you can only use your web application, and this is a solution that is not tested, you could add an ignored route to your routing mechanism like:
如果您只能使用web应用程序,而这是一个没有经过测试的解决方案,您可以添加一条被忽略的路由到您的路由机制,比如:
routes.IgnoreRoute("{*allignore}", new {allignore=@".*\.ignore(/.*)?"});
and upon check that the IP is banned, simple redirect using for example Response.Redirect()
to your site, to a .ignore
path... or, why not redirecting that request to google.com
just for the fun of it?
在检查IP被禁止后,使用简单的重定向,例如Response.Redirect()到您的站点,到。ignore path…或者,为什么不把这个请求重定向到google。com呢?