how to get ip and how to check in login page

Posted by Suneel161 under Regular Expressions on 6/14/2010 | Views : 1762 | Status : [Member] | Replies : 3
i've 3 modules in my project,only the particular client ip need to work in admin module.
how to get client ip and how to check in user login page..




Responses

Posted by: Vuyiswamb on: 6/14/2010 [Member] [MVP] [Administrator] NotApplicable

Up
0
Down
To Get a Client IP Adress use this code

Request.UserHostAddress()


and to code a login use this
http://www.dotnetfunda.com/articles/article808-how-to-write-a-simple-login-page-in-aspnet-.aspx

Thank you for posting at Dotnetfunda
[Administrator]

Suneel161, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Skraghava on: 6/14/2010 [Member] Starter

Up
0
Down
Hi

This will give host address and not IP Adress..

Can you please let me know how to get IP Adress.

Thanks and regards,
Raghavendra SK

Suneel161, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Yasirkudallur on: 6/15/2010 [Member] Starter

Up
0
Down
The following snippet gets the IP address of the machine from which the client visited the website.

string ipaddress;//ASsigning a variable to store the IP address

ipaddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];//Explained below

if (ipaddress == "" || ipaddress == null)

ipaddress = Request.ServerVariables["REMOTE_ADDR"];

When users are behind any proxies or routers the REMOTE_ADDR returns the IP Address of the router and not the client user's machine. Hence first we need to check HTTP_X_FORWARDED_FOR, since when client user is behind a proxy server his machine's IP Address the Proxy Server's IP Address is appended to the client machine's IP Address. If there are multiple proxy servers the IP Addresses of all of them are appended to the client machine IP Address.

While running this application on your machine it will show IP Address 127.0.0.1 since your client and server is the same machine. So no need to worry deploy it on server you'll see the results.

Code for a login use the below link:
http://www.dotnetfunda.com/articles/article808-how-to-write-a-simple-login-page-in-aspnet-.aspx



Hence we need to first check HTTP_X_FORWARDED_FOR and then REMOTE_ADDR.

Suneel161, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response