protected void btnProceed_Click(object sender, EventArgs e) { try { Introduction objRequest = new Introduction(); Response.Cookies["TOKEN"].Value = Guid.NewGuid().ToString(); Response.Cookies["TOKEN"].Expires = DateTime.Now.AddDays(1); objRequest.ID = new Guid(Response.Cookies["TOKEN"].Value); objRequest.MOBILE = txtMobile.Text.Trim(); objRequest.EMAIL = txtEmail.Text.Trim(); objGLocation = new GeoLocation(); objGLocation = GetUserIP(); objRequest.IPADDRESS = objGLocation.ip; hdnOTP.Value = objWebsite.GenerateRandomNo(100000, 999999).ToString(); objRequest.OTP = Convert.ToInt32(hdnOTP.Value); objWebsite.InsertWebsiteIntroduction(objRequest); divwelcmForm.Attributes.CssStyle.Add("display", "none"); divOTP.Attributes.CssStyle.Add("display", "block"); //TODO:Comment for beta and live Response.Redirect("/Default.aspx", false); } catch (Exception ex) { objWebsite.InsertWebsiteLog(Request.Cookies["TOKEN"].Value, "welcome.aspx.cs", "btnProceed_Click", "", ex.ToString()); } }
public GeoLocation GetUserIP() { GeoLocation result = new GeoLocation(); try { string url = "http://freegeoip.net/json/"; WebClient wc = new WebClient(); wc.Proxy = null; MemoryStream ms = new MemoryStream(wc.DownloadData(url)); var sr = new StreamReader(ms); var myStr = sr.ReadToEnd(); ms.Dispose(); result = JsonConvert.DeserializeObject<GeoLocation>(myStr); } catch (Exception ex) { objWebsite.InsertWebsiteLog(Request.Cookies["TOKEN"].Value, "welcome.aspx.cs", "GetUserIP", JsonConvert.SerializeObject(result), ex.ToString()); } return result; }
protected void Page_Load(object sender, EventArgs e) { try { if (!IsPostBack) { //Check IP Address to allow only Indian Users objGLocation = new GeoLocation(); //objGLocation = GetUserIP(); objGLocation.country_code = "IN"; if (objGLocation.country_code == "IN") { divContainer.Visible = true; divError.Visible = false; divOTP.Attributes.CssStyle.Add("display", "none"); } else { divContainer.Visible = false; divError.Visible = true; } } if (Response.Cookies["USERID"].Value != null || Response.Cookies["TOKEN"].Value != null) { Response.Redirect("~/default.aspx", false); } } catch (Exception ex) { objWebsite.InsertWebsiteLog("", "welcome.aspx.cs", "Page_Load", "", ex.ToString()); } }