Faith_Akira
New Member
I have a website that, in order to work properly, needs to have a XML file appended to all its URLs, let's say the file is called \[code\]module-1.xml\[/code\]. In order to keep those URls clean, I wrote a IHttpModule's that uses the \[code\]HttpContext.Current.RewritePath\[/code\] to do the appending job inside the \[code\]OnBeginRequest\[/code\] event.The IHttpModule looks pretty simple and works:\[code\]public void OnBeginRequest(Object s, EventArgs e){ string url = HttpContext.Current.Request.Url.AbsolutePath; if (url.EndsWith(".aspx")) HttpContext.Current.RewritePath(url + "?module-1.xml");}\[/code\]Now, I wanted to use the session variable to detect when a user decides to switch the website from \[code\]model-1.xml\[/code\] to \[code\]model-2.xml\[/code\] and have my code changed as follow:\[code\]public void OnBeginRequest(Object s, EventArgs e){ string url = HttpContext.Current.Request.Url.AbsolutePath; if (url.EndsWith(".aspx")) { if (HttpContext.Current.Session["CurrentMode"] == "1") HttpContext.Current.RewritePath(url + "?module-1.xml"); else if(HttpContext.Current.Session["CurrentMode"] == "2") HttpContext.Current.RewritePath(url + "?module-2.xml"); }}\[/code\]From what I have found, the session can be accessed inside a module but not from inside the \[code\]OnBeginRequest\[/code\] event which is the only event where \[code\]HttpContext.Current.RewritePath\[/code\] can be made functional (at least from all the testing I have been doing). Is my assumption correct? And if it is, what alternative could I use? Create a custom Session variable? Should I read from a txt file or from a DB in order to know what module the user is looking at? How could I keep track of a user from within the module?