string userip = Request.UserHostAddress;
                    string killips1 = killips();
                    string[] arr1 = killips1.Split('|');
                    string[] arru1 = userip.Split('.');
                    foreach (string i in arr1)
                    {
                        string[] arr1_1 = i.Split('.');
                        bool bolkill = true;
                        if ((arru1[0] != arr1_1[0]) && (arr1_1[0] != "*"))
                        {
                            bolkill = false;
                        }
                        if ((arru1[1] != arr1_1[1]) && (arr1_1[1] != "*"))
                        {
                            bolkill = false;
                        }
                        if ((arru1[2] != arr1_1[2]) && (arr1_1[2] != "*"))
                        {
                            bolkill = false;
                        }
                        if ((arru1[3] != arr1_1[3]) && (arr1_1[3] != "*"))
                        {
                            bolkill = false;
                        }
                        if (bolkill == true)
                        {
                            Response.Write("受限IP,拒绝访问");
                            Response.End();
                        }
提示索引超出了数组界限,请教!

解决方案 »

  1.   

    这个问题,你只要稍加调试就知道原因在哪里了?比方说,你查看一下数组的length
      

  2.   

    调试的时候监视一下arru1,arr1_1数组的个数和其中的值.应该可以找到问题的.
      

  3.   

    程序写得有问题。应添加判断UserHostAddress传入22.33.44你的程序就挂了
      

  4.   

    int s = arr1_1.Length;
                            Response.Write(s);
                            int h = arru1.Length;
                            Response.Write(h);
    返回的是4
    kssys()讲应该添加判断在哪里呢
      

  5.   

    1.判断用户IP
    if(arru1.GetUpperBound(0)<3)
    {
      //用户不是合法IP,添加处理
    }
    foreach (string i in arr1)
      

  6.   

    2.判断被禁止的IP
    string[] arr1_1 = i.Split('.');
    if(arr1_1.GetUpperBound(0)<3) continue; //被禁止的IP不合法,跳过
    bool bolkill = true;
      

  7.   

    那我返回数组的leght都是4,怎么会出现这种错误呢?