protected void Page_Load(object sender, EventArgs e) { Announcement announce = decerealizer.GetAnnouncement(); VisitCounter counter = decerealizer.GetVisitCounter(); // If the session has not been counted, count it then mark it counted. if ((string)System.Web.HttpContext.Current.Session["counted"] != "yes") { counter.numOfVisits++; counter.serialize(); Session["counted"] = "yes"; } // Displays this banner if logged in. if ((string)Session["loggedIn"] == "yes") { loggedInBanner.Visible = true; } else { loggedInBanner.Visible = false; } // Checks for and sets announcement if (announce.onOrOff) { txtAnnounce.Visible = true; Literal1.Text = announce.announce; } else { txtAnnounce.Visible = false; } }
public void FindRefrall(int TodayTotal) { using (MashadCarpetEntities db = new MashadCarpetEntities()) { VisitCounter c = new VisitCounter(); TodayTotal = TodayTotal + 1; c.ClientIP = Request.UserHostAddress; c.VisitDate = DateTime.Now; c.VisitCount = 1; c.TotalVisit = TodayTotal; if (Request.UrlReferrer != null) { c.RefrallPage = Request.UrlReferrer.ToString(); } else { c.RefrallPage = "ورود مستقیم"; } System.Web.HttpBrowserCapabilities browser = Request.Browser; c.Browser = browser.Type; c.OS = ReturnOS(); db.VisitCounter.Add(c); db.SaveChanges(); } }
public void Init(HttpApplication application) { application.BeginRequest += (sender, e) => { var ip = Asp.ClientIP; // IP 黑名单过滤 if (IPFilter.IsBanned(ip)) { IO.Trace("BanIP : " + ip); Logger.Log("BanIP", ip); HttpContext.Current.Request.Abort(); return; } // 访问频率限制(10秒一个周期计算访问次数) if (SiteConfig.Instance.VisitDensity != null) { if (VisitCounter.IsHeavy(ip, "", 10, SiteConfig.Instance.VisitDensity.Value * 10)) { Logger.LogDb("OverFreqency"); IPFilter.Ban(ip, "访问过于频繁被禁", SiteConfig.Instance.BanMinutes); } } }; }
protected void Session_Start(object sender, EventArgs e) { CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("MS_AzureStorageAccountConnectionString")); CloudTableClient tableClient = storageAccount.CreateCloudTableClient(); CloudTable table = tableClient.GetTableReference("VisitorCounter"); DateTime KRT = DateTime.Now.AddHours(9); string rowKey = ""; if (KRT.Hour > 0 && KRT.Hour < 10) { rowKey = "0" + KRT.Hour.ToString() + "시"; } else { rowKey = KRT.Hour.ToString() + "시"; } string partitionKey = KRT.Year.ToString() + "년"; if (KRT.Month > 0 && KRT.Month < 10) { partitionKey += "0" + KRT.Month.ToString() + "월"; } else { partitionKey += KRT.Month.ToString() + "월"; } if (KRT.Day > 0 && KRT.Day < 10) { partitionKey += "0" + KRT.Day.ToString() + "일"; } else { partitionKey += KRT.Day.ToString() + "일"; } TableOperation retrieveOperation = TableOperation.Retrieve <VisitCounter>(partitionKey, rowKey); // Execute the retrieve operation. TableResult retrievedResult = table.Execute(retrieveOperation); VisitCounter retrievedEntity = (VisitCounter)retrievedResult.Result; if (retrievedEntity == null) { VisitCounter newVisitor = new VisitCounter(partitionKey, rowKey); TableOperation insertOperation = TableOperation.Insert(newVisitor); table.Execute(insertOperation); } else { retrievedEntity.Number += 1; TableOperation updateOperation = TableOperation.Replace(retrievedEntity); table.Execute(updateOperation); } }
protected void Page_Load(object sender, EventArgs e) { // First load OR Postback, checks if user is logged in. if (!Methods.isLoggedIn()) { // Redirects to login page. Response.Redirect("~/PagesPublic/Pass.aspx"); } else { // If user is logged in and this is a First Load, sets up the announcment form based on config from ann. if (!IsPostBack) { if (ann.onOrOff == true) { chkJumbo.Checked = true; } else { chkJumbo.Checked = false; } if (ann.announce != "" && ann.announce != null) { txtJumbo.Text = ann.announce.Replace("<br />", "\r\n"); txtJumbo.Visible = false; } } // First load OR Postback, if checked box checked, displays announcment text box. if (chkJumbo.Checked) { txtJumbo.Visible = true; } else { txtJumbo.Visible = false; } // First load OR postback, sets page visitor counter. VisitCounter counter = decerealizer.GetVisitCounter(); lblVisits.Text = counter.numOfVisits.ToString(); } }
public async Task Invoke(HttpContext context) { var visitorId = context.Request.Cookies["VisitorId"]; if (visitorId == null) { visitorId = Guid.NewGuid().ToString(); //don the necessary staffs here to save the count by one context.Response.Cookies.Append("VisitorId", visitorId, new CookieOptions() { Path = "/", HttpOnly = true, Secure = false, Expires = DateTime.Now.AddMonths(1) }); } VisitCounter.Visit(visitorId); await _requestDelegate(context); }
public VisitCountingFilterAttribute(VisitCounter visitCounter) { _visitCounter = visitCounter; }