0

In my application i want to check that the url is accessed in the particular ip address. Only one time the page needs to be displayed and for the next time navigating to that page the page should not come.

How can i achieve this?

Regards, Prasad

Vara Prasad.M
  • 1,530
  • 9
  • 31
  • 55

5 Answers5

3

I've used this recently to identify users IP-Address(es) to log them on failed logins:

// Look for a proxy address first
var IP = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
//Trim and lowercase IP if not null
if (IP != null)
{
    IP = IP.ToLower().Trim();
}
if (IP == null || IP.Equals("unknown"))
{
    //If IP is null use different detection method else pull the correct IP from list.
    IP = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"].ToLower().Trim();
}

String[] IPs = null;
if (IP.IndexOf(",") > -1)
{
    IPs = IP.Split(',');
}
else
{
    IPs = new string[] { IP };
}

( note: converted from VB.NET )

Tim Schmelter
  • 450,073
  • 74
  • 686
  • 939
2

Are you actually looking to display the page once per client, or genuinely once per IP?

If it's client machine based, then have that page store a cookie and check for it's presence to determine if the page has been visited before.

pswillies
  • 126
  • 4
2

You can try storing the IP address in the database or you can make use of a cookie variable. Read more about Cookies

Razvan Trifan
  • 534
  • 2
  • 6
1

as suggested and described here: How to get a user's client IP address in ASP.NET?

you can check this in the Page_Load

Request.ServerVariables["REMOTE_ADDR"];

and if access was already done once you can use Server.Transfer to move to another page (like a warning page or back to home page etc...)

the way you persist which IP accessed your page once is up to you and your needs, Session, Application Cache, database, cookies...

Community
  • 1
  • 1
Davide Piras
  • 43,984
  • 10
  • 98
  • 147
0

When the page is loaded get the IP-address and store it in a database. Then, also when the page is loaded, check the IP against a possible entry in the database. If it doesn't exist, store it and load the page. If it aleady exists, redirect the user or something.

Abbas
  • 14,186
  • 6
  • 41
  • 72