/// <summary> /// Initializes the EmergencyContext object and stores it in HttpContext.Items bag. /// </summary> public static EmergencyContext CreateContext() { EmergencyContext eContext = null; //make sure one does not exist first HttpContext current = HttpContext.Current; if (current != null) { if (current.Items[_itemsKey] != null) { throw new Exception(_itemsKey + " Already Exists"); } else { eContext = new EmergencyContext(); current.Items.Add(_itemsKey, eContext); } } else { throw new Exception("HttpContext.Current does not exist"); } return(eContext); }
void context_BeginRequest(object sender, EventArgs e) { HttpApplication app = (HttpApplication)sender; HttpContext currContext = app.Context; //Since we only want to do this for .aspx files to cutdown on DB requests, //we need to check the extension. string currPath = currContext.Request.Path; if (!string.IsNullOrEmpty(currPath)) { string ext = VirtualPathUtility.GetExtension(currPath); //.aspx ext = ext.ToLower(); if (ext != ".aspx") { return; } } //First see if there is an emergency and store it in the HttpContext. (So we do not have //to keep going back to the db. EmergencyContext context = EmergencyContext.CreateContext(); if (context == null) { //Log error } else { //Secondly if we need to redirect ALL requests to the emergency page then we should //redirect. if (context.RedirectAllPages) { //check to see if this is the emergency url. Note since the emergency page is a flat //aspx, it will not be a prettyURL and therefore not rewritten. if (currContext.Request.RawUrl.ToLower() != context.EmergencyUrl.ToLower()) { currContext.Response.Redirect(context.EmergencyUrl, true); } } } }
protected override void OnInit(EventArgs e) { this.Visible = false; this.eContext = EmergencyContext.Current; //We should not show this on the print version. bool isPrint = Strings.ToBoolean(Page.Request.Params["print"]); if (this.eContext != null) { if (!isPrint && this.eContext.InEmergency && !string.IsNullOrEmpty(this.eContext.BannerText) && !IsEmergencyPage()) { //Should not show this if it is the emergency page also... //Turn on only in an emergency && only if there is some text for the banner. this.Visible = true; } } this.CssClass = "EmergencyAlertBanner"; }
protected override void RenderContents(HtmlTextWriter output) { EmergencyContext ctx = EmergencyContext.Current; if (ctx == null || !ctx.InEmergency) { output.RenderBeginTag(HtmlTextWriterTag.H1); output.Write("There is currently no emergency."); output.RenderEndTag(); } else { output.RenderBeginTag(HtmlTextWriterTag.H1); output.Write(ctx.Title); output.RenderEndTag(); output.AddAttribute(HtmlTextWriterAttribute.Class, "message"); output.RenderBeginTag(HtmlTextWriterTag.Div); output.Write(ctx.Information); output.RenderEndTag(); } }