0

I have some web site with two .aspx files (Default.aspx and Default2.aspx). In Default.aspx.cs I have this simple code:

    using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string ip = Request.UserHostAddress.ToString();
        bool IsCorrectIP = ip.StartsWith("194.100.");
        if (IsCorrectIP)
        {
            Server.Transfer("Default2.aspx");
        }
    }
}

When I run my Default.aspx (locally) on IP address which doesn´t start with 194.100.(xxx), Default.aspx is still displayed. Could someone help me how to allow only certain IP in this sample ?

1 Answers1

0

Your condition should look like this, add a NOT(!) before IsCorrectIP:

if (!IsCorrectIP)
{
    Server.Transfer("Default2.aspx");
}
sachin
  • 2,341
  • 12
  • 24