/// <summary> /// public method to return single instance of class /// </summary> /// <returns>single instance of class</returns> public static TransferUrlList GetInstance() { // see if instance already created if (instance == null) { // create the instance instance = new TransferUrlList(); urls = new StringDictionary(); String xmlFilePath = HttpContext.Current.Request.MapPath(ConfigurationSettings.AppSettings.Get("TransferURL")); // read list of transfer URLs from XML file try { using (XmlReader reader = XmlReader.Create(xmlFilePath)) { while (reader.Read()) { if (reader.LocalName == "item") { // populate StringDictionary urls.Add(reader.GetAttribute("name"), reader.GetAttribute("url")); } } } } catch (Exception ex) { throw new Exception("Transfer url list: Cannot load URL transfer list", ex); } } return(instance); }
/// <summary> /// use features of the request (user, browser, IP address, etc.) /// to decide how to handle the request, and which page to show /// this example looks for specific items in the query string /// that indicate the required target (such as "CustomerList") /// using a dictionary of values loaded from an XML disk file /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void MyPreRequestHandler(Object sender, EventArgs e) { // get Singleton list of transfer URLs TransferUrlList urlList = TransferUrlList.GetInstance(); // get the current request query string String reqTarget = HttpContext.Current.Request.QueryString["target"]; if (reqTarget != null && reqTarget != String.Empty) { // see if target value matches a transfer URL // by querying the list of transfer URLs // method returns the original value if no match String transferTo = urlList.GetTransferUrl(reqTarget); try { // transfer to the specified URL HttpContext.Current.Server.Transfer(transferTo, true); } catch { } } }