protected void BindFields() { SurveyIPRangeData data = new SurveyIPRange().GetAllSurveyIPranges(((PageBase)Page).SurveyId); DataView dv1 = data.DefaultViewManager.CreateDataView(data.Tables[0]); // when no results found we add new empty row and clear it cells if (dv1.Count == 0) { dv1.AddNew(); gvIPRanges.DataSource = dv1; gvIPRanges.DataBind(); foreach (TableCell cell in gvIPRanges.Rows[0].Cells) { cell.Controls.Clear(); cell.Controls.Add(new Literal()); } gvIPRanges.Rows[0].Visible = false; } else { gvIPRanges.DataSource = data.SurveyIPRange.Rows; gvIPRanges.DataBind(); } }
private bool IsValidIP() { SurveyIPRangeData ranges = new SurveyIPRange().GetAllSurveyIPranges(this._surveyId); if (ranges.SurveyIPRange.Count == 0) return true; // long curreneIP = Ip4ToInt(HttpContext.Current.Request.UserHostAddress); long curreneIP = Ip4ToInt((HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"] != null) ? HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"] : HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]); foreach (SurveyIPRangeData.SurveyIPRangeRow row in ranges.SurveyIPRange) if (curreneIP >= Ip4ToInt(row.IPStart) && curreneIP <= Ip4ToInt(row.IPEnd)) return true; return false; }