Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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);
        }