void BeginRequest(object sender, EventArgs e) { HttpApplication application = (HttpApplication)sender; HttpRequest request = application.Context.Request; PermanentlyMovedConfig connfig = PermanentlyMovedConfig.GetPermanentlyMovedConfig(); PermanentlyMoved permanentlyMoved = connfig.Find(pm => request.Path.Equals(pm.SourceUrl, StringComparison.OrdinalIgnoreCase)); if (permanentlyMoved == null) return; string newUrl = permanentlyMoved.TargetUrl; if (permanentlyMoved.WithQuery) { string query = request.QueryString.ToString(); if (!string.IsNullOrEmpty(query)) { if (!newUrl.Contains("?")) newUrl += "?"; else newUrl += "&"; newUrl += query; } } PermanentlyMovedUtility.Redirect(newUrl); }
public static PermanentlyMovedConfig GetPermanentlyMovedConfig() { if (permanentlyMovedConfig == null) { string configPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "PermanentlyMoved.xml"); string xml = string.Empty; using (StreamReader reader = new StreamReader(configPath, Encoding.UTF8)) { xml = reader.ReadToEnd(); } permanentlyMovedConfig = XmlUtility.Deserialize <PermanentlyMovedConfig>(xml); } return(permanentlyMovedConfig); }