I need to block one IP address or class in asp.net
Can anyone help me with the code? And how to implement?
Thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can get the IP address of the client using the
HttpRequest.UserHostAddressproperty (an instance can be accessed usingthis.Requestfrom any page or using static propertyHttpContext.Current).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.
You’ll probably want to check this for every request, which can be done either in the
OnInitmethod of every page (that you want to block) or in theBeginRequestevent of the application (typically inGlobal.asax).If you detect a blocked address, you can output an empty (placeholder) page using
Server.Transfermethod (Response.Endwould be another alternative, but that simply cuts the page – returning an empty page, whileServer.Transferallows you to output some message to the client).