protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { Brand.Text = "Attention Tasks"; Session["AccessCode"] = ""; Session["Ip"] = Request.ServerVariables["REMOTE_ADDR"]; if (!string.IsNullOrEmpty(Request.QueryString["i"])) { Session["AccessCode"] = Request.QueryString["i"]; } string imageUrl = "~/controls/stimulus/award_silver.png"; if (Session["AccessCode"].ToString().Length > 0) { imageUrl = "~/controls/stimulus/award_" + AwardLevel(Session["AccessCode"].ToString()) + ".png"; //Image1.ImageUrl = imageUrl; } Image1.ImageUrl = imageUrl; var download = new Download { DId = 0, DownloadTime = DateTime.Now, Op = 0, AccessCode = Session["AccessCode"].ToString(), WorkerId = "", Ip = Session["Ip"].ToString() }; using (SignalAwardContext db = new SignalAwardContext()) { db.Downloads.Add(download); db.SaveChanges(); } } }
protected void btnDownload_Click(object sender, EventArgs e) { string accessCode = Session["AccessCode"].ToString(); var download = new Download { DId = 0, DownloadTime = DateTime.Now, Op = 1, AccessCode = accessCode, WorkerId = "", Ip = Session["Ip"].ToString() }; using (SignalAwardContext db = new SignalAwardContext()) { db.Downloads.Add(download); db.SaveChanges(); } string fileName = accessCode + ".pdf"; string filePath = "~/Cert/Certs/" + fileName; if (File.Exists(Server.MapPath(filePath))) { Response.ContentType = "Application/pdf"; Response.AppendHeader("Content-Disposition", "attachment; filename=" + fileName); Response.TransmitFile(Server.MapPath(filePath)); Response.End(); } else { LabelDebug.Text = "Oh snap! Sorry, we cannot find your certificate. We will try to contact you by email."; LabelDebug.Visible = true; SaveExeption("File not found", "Download", 40); } }