Click here to Skip to main content
15,901,426 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

I have to perform authentication in web service means only selected IP's will have access to web service. I have to match that IP's from the database.

For that do i need to write that code in the Web Method or is their any other optimized way for this.

I am using this code for getting Client IP.

string sClientIP = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];

if(sClientIP == "" || sClientIP == null)

sClientIP = Request.ServerVariables["REMOTE_ADDR"];

Please help.......

1 solution

Get the client's IP, and call a stored proc with that IP as a parameter, and return the appropriate record (if found). If no records were returned, it's an invalid IP.

There's no "optimization" needed.
Share this answer
Member 7217874 6-Aug-10 14:41pm    
Ok. But my question is their any thing filters that we can use it in web.config.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900