Exemplo n.º 1
0
        private void ContextOnBeginRequest(object sender, EventArgs eventArgs)
        {
            var httpContext = ((HttpApplication)sender).Context;

            if (httpContext.Request.Url.AbsolutePath != "/" && httpContext.Request.Url.AbsolutePath.EndsWith("/", StringComparison.Ordinal))
            {
                var redirect = httpContext.Request.Url.AbsolutePath;
                redirect = redirect.Remove(redirect.Length - 1);
                httpContext.Response.Clear();
                httpContext.Response.Status     = "301 Moved Permanently";
                httpContext.Response.StatusCode = 301;
                httpContext.Response.AddHeader("Location", redirect);
                httpContext.Response.End();
                return;
            }

            var service = new SeoRoutingService();

            var result = service.Route(httpContext.Request.Url);

            if (result == null)
            {
                return;
            }

            httpContext.Items["HTTPCONTEXT:SEOROUTING:RESULT"] = result;

            httpContext.RewritePath("/");
        }
Exemplo n.º 2
0
        public ActionResult Index()
        {
            var seoRoutingResult = HttpContext.Items["HTTPCONTEXT:SEOROUTING:RESULT"] as SeoRoutingResult;
            var details          = new SeoRoutingService().ConstructSeoDetails(HttpContext.Request.RawUrl, seoRoutingResult);

            return(View(details));
        }