protected void Page_Load(object sender, EventArgs e) { //Authorization checking if (AppSettingsUtility.GetBool(AppSettingsKeys.EnableAuthorization) && Session[SiteConstants.SESSION_USER_AUTHORIZED] == null) { string logonURL = AppSettingsUtility.GetString(AppSettingsKeys.LogOnURL); string returnURL = HttpUtility.UrlEncode(Request.Url.ToString()); string domain = Request.Url.Host; logonURL = logonURL.Replace("[returnURL]", returnURL).Replace("[authDomain]", domain); Response.Redirect(logonURL); } if (System.Web.HttpContext.Current.Session[SiteConstants.SESSION_USER] != null) { TSM.Entity.User user = (TSM.Entity.User)System.Web.HttpContext.Current.Session[SiteConstants.SESSION_USER]; string mail = user.Email; string host = mail.Split('@')[1].ToString(); string mailCred = "intracen.org"; // "intracen.org"; if (host != mailCred) { ScriptManager.RegisterStartupScript(this, GetType(), "authorized", "alert('You are not authorized to enter.'); window.close();", true); } } }
/// <summary> /// Application Error /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Application_Error(object sender, EventArgs e) { Exception exception = Server.GetLastError(); HttpException httpException = exception as HttpException; ErrorLog.WriteLog("GlobalError", "Application_Error", exception, string.Empty); if (AppSettingsUtility.GetBool(AppSettingsKeys.EnableCustomError)) { if (httpException != null && httpException.GetHttpCode() == 404) { Response.Redirect("/page-not-found/"); } else { Response.Redirect("/error/"); } } }
public ActionResult download(string id, string isPublic) { try {//intracen string UrlReferrerForDoc = Request.UrlReferrer.ToString(); bool contains = UrlReferrerForDoc.Contains("intracen"); if (contains == false) { urlPathForDoc = UrlReferrerForDoc; } } catch { } if (isPublic == "ITCdownload") { //Authorization checking if (AppSettingsUtility.GetBool(AppSettingsKeys.EnableAuthorization) && Session[SiteConstants.SESSION_USER_AUTHORIZED] == null) { string logonURL = AppSettingsUtility.GetString(AppSettingsKeys.LogOnURL); string returnURL = HttpUtility.UrlEncode(Request.Url.ToString()); string domain = Request.Url.Host; logonURL = logonURL.Replace("[returnURL]", returnURL).Replace("[authDomain]", domain); return(Redirect(logonURL)); } } if (System.Web.HttpContext.Current.Session[SiteConstants.SESSION_USER] != null) { TSM.Entity.User user = (TSM.Entity.User)System.Web.HttpContext.Current.Session[SiteConstants.SESSION_USER]; string mail = user.Email; string host = mail.Split('@')[1].ToString(); string mailCred = "intracen.org"; // "intracen.org"; if (host != mailCred) { return(Content("<script language='javascript' type='text/javascript'>alert('You are not authorized to download the document.'); window.close();</script>")); } } string zipFolderPath = Server.MapPath("~/UploadedFiles/Documents/tempZip/"); string zipFilePath = "document_" + DateTime.Now.Ticks.ToString() + ".zip"; if (!Directory.Exists(zipFolderPath)) { Directory.CreateDirectory(zipFolderPath); } string folderPath = Server.MapPath("~/UploadedFiles/Documents/"); Guid recordID = Guid.Empty; if (!string.IsNullOrEmpty(id)) { Guid.TryParse(id, out recordID); } if (recordID == null || recordID == Guid.Empty) { return(Redirect("/")); } var documents = RecordService.GetDocuments(recordID); if (documents == null || documents.Count == 0) { return(Redirect("/")); } List <string> files = new List <string>(); foreach (var document in documents) { string file = folderPath + document.Path; files.Add(file); } string ZipFile = zipFolderPath + zipFilePath; ZipHelper.WriteZipFile(files, ZipFile, 6); byte[] fileBytes = System.IO.File.ReadAllBytes(ZipFile); string fileName = "document.zip"; Guid documentID = Guid.Empty; if (!string.IsNullOrEmpty(id)) { Guid.TryParse(id, out documentID); } var model = new DocumentDetailModel(); bool isExists = model.Populate(documentID, urlPathForDoc); model.ZipFilePath = ZipFile.ToString(); model.LoginStat = "Y"; return(View("~/Views/Document/Index.cshtml", model)); }