string Url=Request.QueryString["techsupporturl"].ToString(); IISCapture.TroubleTicket oTicket = new IISCapture.TroubleTicket(); msSessionKey = oTicket.LoadNewSessionToApplication(System.Web.HttpContext.Current,Url);
IISCapture.TroubleTicket oTicket = new IISCapture.TroubleTicket(); oTicket.LoadSessionFromApplication(System.Web.HttpContext.Current,this.TextBox1.Text); oTicket.TransferToUrl(System.Web.HttpContext.Current);
using System; using System.Web; using System.Web.SessionState; using System.Data.SqlClient; using System.Diagnostics; using System.Collections; using System.Collections.Specialized; using System.IO; using System.Text; namespace IISCapture { public class Log : IHttpModule { HttpApplication HttpApp; HttpRequest HttpReq; HttpResponse HttpRes; public void Init(HttpApplication App) { // First event in the event chain App.BeginRequest += new EventHandler(OnBeginRequest); // Session state for the request isn't available until this event fires. App.AcquireRequestState += new EventHandler(AcquireRequestState); // If you want to alter the output stream on the fly, do it here. App.ReleaseRequestState += new EventHandler(ReleaseRequestState); } // Application Context Events private void OnBeginRequest(object sender, EventArgs eventArgs ) { HttpApp = (HttpApplication)sender; HttpReq = HttpApp.Context.Request; HttpRes = HttpApp.Context.Response; try { } catch (Exception err) { ProcessError(err.Message); } } private void AcquireRequestState(object sender, EventArgs eventArgs ) { string Ticket=""; string Url=""; try { // Reload application cache with the user's session info and // also grab the last posted form elements and their values. if (this.IsSessionInTechSupportMode()==true) { IISCapture.TroubleTicket oTicket = new IISCapture.TroubleTicket(); Ticket = HttpApp.Context.Session[IISCapture.TroubleTicket.TechSupportKey].ToString(); Url = HttpApp.Context.Session[IISCapture.TroubleTicket.TechSupportUserLastPage].ToString(); oTicket.LoadSessionToApplication(HttpApp.Context,Ticket,Url); oTicket.LoadFormToApplication(HttpApp.Context,Ticket); return; } // get the problem user's session info again. if (this.IsSessionATechSupportRep()==true) { IISCapture.TroubleTicket oTicket = new IISCapture.TroubleTicket(); Ticket = HttpApp.Context.Session[IISCapture.TroubleTicket.TechSupportKey].ToString(); oTicket.LoadSessionFromApplication(HttpApp.Context,Ticket); // Here is a sample of how to read the posted form values from the user // needing technical support: try { object[,] oValues = oTicket.GetFormFromApplication(HttpApp.Context,Ticket); for(int i=0;i<=oValues.GetUpperBound(1);i++) { Debug.Write(oValues[0,i].ToString() + ": "); Debug.WriteLine(oValues[1,i].ToString()); } } catch { } } } catch (Exception err) { ProcessError(err.Message); } } private void ReleaseRequestState(object sender, EventArgs eventArgs ) { // This event is a good choice for apply filters to the output // stream to the browser/client. By overriding the filter, you // can modify the output stream after all the response.write's are // done and before it gets to the browser. // Just add your own business rules to determine whether a filter // should be applied at all. try { if(HttpRes.ContentType != "text/html") { return; } // HttpRes.Filter = new IISCapture.FilterHtml(ref CaptureSession,HttpRes.Filter); } catch (Exception err) { ProcessError(err.Message); } } // Custom methods private bool IsSessionInTechSupportMode() { bool Ret = false; try { if (HttpApp.Context.Session[IISCapture.TroubleTicket.TechSupportEnable] != null) { if (HttpApp.Context.Session[IISCapture.TroubleTicket.TechSupportEnable].ToString() =="1") { Ret=true; } } } catch { } return Ret; } private bool IsSessionATechSupportRep() { bool Ret = false; try { if (HttpApp.Context.Session[IISCapture.TroubleTicket.TechSupportRep] != null) { if (HttpApp.Context.Session[IISCapture.TroubleTicket.TechSupportRep].ToString() =="1") { Ret=true; } } } catch { } return Ret; } private void ProcessError(string ErrMsg) { HttpApp.Context.Response.Write(ErrMsg); } public void Dispose(){} } }
using System; using System.Web; using System.Collections; using System.Text; using System.IO; using System.Diagnostics; namespace IISCapture { public class TroubleTicket { public const string TechSupportUserLastPage = "TechSupportUserLastPage"; public const string TechSupportEnable = "TechSupportEnable"; public const string TechSupportKey = "TechSupportKey"; public const string TechSupportRep = "TechSupportRep"; public const string TechSupportCache = "TechSupportCache_"; public const string TechSupportCacheSession = "Session_"; public const string TechSupportCacheForm = "Form_"; public TroubleTicket() { } public void TransferToUrl(HttpContext oContext) { try { oContext.Response.Redirect(oContext.Session[TechSupportUserLastPage].ToString()); } catch (Exception) { throw; } } public string LoadNewSessionToApplication(HttpContext oContext,string GotoUrl) { string TroubleTicket=""; try { TroubleTicket = System.Guid.NewGuid().ToString(); LoadSessionToApplication(oContext,TroubleTicket,GotoUrl); LoadFormToApplication(oContext,TroubleTicket); } catch (Exception) { throw; } return TroubleTicket; } public void LoadSessionToApplication(HttpContext oContext,string TroubleTicket,string GotoUrl) { try { oContext.Session[TechSupportUserLastPage] = GotoUrl; oContext.Session[TechSupportKey] = TroubleTicket; object[,] oValues = new object[2,oContext.Session.Keys.Count]; for(int i=0;i<oContext.Session.Keys.Count;i++) { oValues[0,i] = oContext.Session.Keys[i].ToString(); oValues[1,i] = oContext.Session[oContext.Session.Keys[i].ToString()]; } oContext.Session[TechSupportEnable] = "1"; if ((object[,])oContext.Cache[TechSupportCache + TechSupportCacheSession + TroubleTicket.Trim()] != null) { oContext.Cache.Remove(TechSupportCache + TechSupportCacheSession + TroubleTicket.Trim()); } oContext.Cache.Insert(TechSupportCache + TechSupportCacheSession + TroubleTicket, _ oValues,null,DateTime.MaxValue, TimeSpan.FromMinutes(10)); } catch (Exception) { throw; } return; } public void LoadFormToApplication(HttpContext oContext,string TroubleTicket) { bool Found=false; try { object[,] oValues = new object[2,oContext.Request.Form.Keys.Count]; for(int i=0;i<oContext.Request.Form.Keys.Count;i++) { oValues[0,i] = oContext.Request.Form.Keys[i].ToString(); oValues[1,i] = oContext.Request[oContext.Request.Form.Keys[i].ToString()]; Found=true; } if ((object[,])oContext.Cache[TechSupportCache + TechSupportCacheForm + TroubleTicket.Trim()] != null) { if (Found==true) { oContext.Cache.Remove(TechSupportCache + TechSupportCacheForm + TroubleTicket.Trim()); } } oContext.Cache.Insert(TechSupportCache + TechSupportCacheForm + _ TroubleTicket,oValues,null,DateTime.MaxValue, TimeSpan.FromMinutes(10)); } catch (Exception) { throw; } return; } public string LoadSessionFromApplication(HttpContext oContext,string TroubleTicket) { string GotoUrl=""; try { object[,] oValues = (object[,])oContext.Cache[TechSupportCache + _ TechSupportCacheSession + TroubleTicket.Trim()]; for(int i=0;i<=oValues.GetUpperBound(1);i++) { oContext.Session[oValues[0,i].ToString()] = oValues[1,i]; } oContext.Session[TechSupportEnable] = "0"; oContext.Session[TechSupportRep] = "1"; GotoUrl = oContext.Session[TechSupportUserLastPage].ToString(); } catch (Exception) { throw; } return GotoUrl; } public object[,] GetFormFromApplication(HttpContext oContext,string TroubleTicket) { object[,] oValues = null; try { oValues = (object[,])oContext.Cache[TechSupportCache + TechSupportCacheForm + TroubleTicket.Trim()]; } catch (Exception) { throw; } return oValues; } } }
Articles
Submit Article
Message Board
Software Downloads
Videos
Rant & Rave
About Us