如何在ASP.NET中阻止IP地址或IP类 [英] How to block IP address or IP classes in ASP.NET
问题描述
我需要在asp.net中阻止一个IP地址或一个类
I need to block one IP address or class in asp.net
有人可以帮助我提供代码吗?以及如何实施?
Can anyone help me with the code? And how to implement?
谢谢
推荐答案
You can get the IP address of the client using the HttpRequest.UserHostAddress
property (an instance can be accessed using this.Request
from any page or using static property HttpContext.Current
).
据我所知,没有标准的方法可以将IP地址与指定范围进行比较,因此您需要自己实现这一点.
As far as I know, there is no standard method that would compare the IP address with a specified range, so you'll need to implement this bit yourself.
您可能需要针对每个请求进行检查,可以在每个页面(要阻止的页面)的 OnInit
方法中或在
You'll probably want to check this for every request, which can be done either in the OnInit
method of every page (that you want to block) or in the BeginRequest
event of the application (typically in Global.asax
).
If you detect a blocked address, you can output an empty (placeholder) page using Server.Transfer
method (Response.End
would be another alternative, but that simply cuts the page - returning an empty page, while Server.Transfer
allows you to output some message to the client).
这篇关于如何在ASP.NET中阻止IP地址或IP类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!