Exemplo n.º 1
0
        /// <summary>
        /// Handles the current request.
        /// </summary>
        /// <param name="context">The current context</param>
        /// <param name="draft">Whether to get the draft or not</param>
        /// <param name="args">Optional url arguments passed to the handler</param>
        protected void HandleRequest(HttpContext context, bool draft, params string[] args)
        {
            if (args != null && args.Length > 0)
            {
                Content content = null;
                int?    width   = null;
                int?    height  = null;

                try {
                    // Get content by id
                    content = Content.GetSingle(new Guid(args[0]), draft);
                    if (content != null)
                    {
                        if (args.Length > 1)
                        {
                            try {
                                width = Convert.ToInt32(args[1]);
                            } catch {}
                        }
                        if (args.Length > 2)
                        {
                            try {
                                height = Convert.ToInt32(args[2]);
                            } catch {}
                        }
                    }
                } catch {
                    // Get content by permalink
                    var perm = Permalink.GetByName(Config.MediaNamespaceId, GetPermalink(args[0], ref width, ref height));

                    if (perm != null)
                    {
                        content = Content.GetByPermalinkId(perm.Id);
                    }
                }

                // Since we don't handle viewing image drafts right now, don't execute the overhead
                // if (content.IsDraft && !Extend.ExtensionManager.Current.MediaProvider.ExistsDraft(content.Id))
                //	 content.IsDraft = false ;

                if (content != null)
                {
                    if (height.HasValue)
                    {
                        content.GetMedia(context, width, height);
                    }
                    content.GetMedia(context, width);
                }
                else
                {
                    context.Response.StatusCode = 404;
                }
            }
            else
            {
                context.Response.StatusCode = 500;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Handles the current request.
        /// </summary>
        /// <param name="context">The current context</param>
        /// <param name="draft">Whether to view the draft</param>
        /// <param name="args">Optional url arguments passed to the handler</param>
        protected virtual void HandleRequest(HttpContext context, bool draft, params string[] args)
        {
            if (Application.Current.RouteHandler != null)
            {
                if (args != null && args.Length > 0)
                {
                    Permalink perm     = null;
                    int       segments = 0;
                    // Accept permalinks with '/' in them
                    for (int n = 0; n < args.Length; n++)
                    {
                        // Check if we can find a permalink in the current namespace
                        perm     = Permalink.GetByName(Config.SiteTreeNamespaceId, args.Subset(0, args.Length - n).Implode("/"));
                        segments = args.Length - n;
                        if (perm != null)
                        {
                            break;
                        }
                    }

                    // If we didn't find a permalink, check for posts in the default namespace
                    if (perm == null && Config.SiteTreeNamespaceId != Config.DefaultNamespaceId)
                    {
                        segments = 0;
                        // Accept permalinks with '/' in them
                        for (int n = 0; n < args.Length; n++)
                        {
                            perm     = Permalink.GetByName(Config.DefaultNamespaceId, args.Subset(0, args.Length - n).Implode("/"));
                            segments = args.Length - n;
                            if (perm != null && perm.Type == Permalink.PermalinkType.POST)
                            {
                                break;
                            }
                        }
                    }

                    if (perm != null)
                    {
                        if (perm.Type == Permalink.PermalinkType.PAGE)
                        {
                            Page page = Page.GetByPermalinkId(perm.Id, draft);

                            if (page != null)
                            {
                                if (!String.IsNullOrEmpty(page.Redirect))
                                {
                                    if (page.Redirect.StartsWith("http://"))
                                    {
                                        context.Response.Redirect(page.Redirect);
                                    }
                                    else
                                    {
                                        context.Response.Redirect(page.Redirect);
                                    }
                                }
                                else
                                {
                                    //
                                    // Call the route handler to route the current page.
                                    Application.Current.RouteHandler.HandlePage(context, perm, page, args.Subset(segments));
                                }
                            }
                            else
                            {
                                context.Response.StatusCode = 404;
                            }
                        }
                        else if (perm.Type == Permalink.PermalinkType.POST)
                        {
                            Post post = Post.GetByPermalinkId(perm.Id, draft);

                            if (post != null)
                            {
                                //
                                // Call the route handler to route the current post.
                                Application.Current.RouteHandler.HandlePost(context, perm, post, args.Subset(segments));
                            }
                            else
                            {
                                context.Response.StatusCode = 404;
                            }
                        }
                    }
                    else
                    {
                        context.Response.StatusCode = 404;
                    }
                }
                else
                {
                    //
                    // Call the route handler to route to the startpage.
                    Application.Current.RouteHandler.HandleStartpage(context);
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Handles the current request.
        /// </summary>
        /// <param name="context">The current context</param>
        /// <param name="draft">Weather to view the draft</param>
        /// <param name="args">Optional url arguments passed to the handler</param>
        protected virtual void HandleRequest(HttpContext context, bool draft, params string[] args)
        {
            if (args != null && args.Length > 0)
            {
                Permalink perm     = null;
                int       segments = 0;
                // Accept permalinks with '/' in them
                for (int n = 0; n < args.Length; n++)
                {
                    perm     = Permalink.GetByName(new Guid("8FF4A4B4-9B6C-4176-AAA2-DB031D75AC03"), args.Subset(0, args.Length - n).Implode("/"));
                    segments = args.Length - n;
                    if (perm != null)
                    {
                        break;
                    }
                }

                if (perm != null)
                {
                    if (perm.Type == Permalink.PermalinkType.PAGE)
                    {
                        Page page = Page.GetByPermalinkId(perm.Id, draft);

                        if (page != null)
                        {
                            if (!String.IsNullOrEmpty(page.Redirect))
                            {
                                if (page.Redirect.StartsWith("http://"))
                                {
                                    context.Response.Redirect(page.Redirect);
                                }
                                else
                                {
                                    context.Response.Redirect(page.Redirect);
                                }
                            }
                            else if (!String.IsNullOrEmpty(page.Controller))
                            {
                                if (page.Controller.StartsWith("~/"))
                                {
                                    context.RewritePath(page.Controller + "/" + args.Subset(segments).Implode("/") + "?permalink=" + perm.Name, false);
                                }
                                else
                                {
                                    context.RewritePath("~/templates/" + page.Controller + "/" + args.Implode("/") +
                                                        (draft ? "?draft=true" : ""), false);
                                }
                            }
                            else
                            {
                                context.RewritePath("~/page/" + args.Implode("/") + (draft ? "?draft=true" : ""), false);
                            }
                        }
                        else
                        {
                            context.Response.StatusCode = 404;
                        }
                    }
                    else if (perm.Type == Permalink.PermalinkType.POST)
                    {
                        Post post = Post.GetByPermalinkId(perm.Id, draft);

                        if (post != null)
                        {
                            if (!String.IsNullOrEmpty(post.Controller))
                            {
                                context.RewritePath("~/templates/" + post.Controller + "/" + args.Implode("/") +
                                                    (draft ? "?draft=true" : ""), false);
                            }
                            else
                            {
                                context.RewritePath("~/post/" + args.Implode("/") + (draft ? "?draft=true" : ""), false);
                            }
                        }
                        else
                        {
                            context.Response.StatusCode = 404;
                        }
                    }
                }
                else
                {
                    context.Response.StatusCode = 404;
                }
            }
            else
            {
                //
                // Rewrite to current startpage
                //
                Page page = Page.GetStartpage();

                if (!String.IsNullOrEmpty(page.Controller))
                {
                    context.RewritePath("~/templates/" + page.Controller, false);
                }
                else
                {
                    context.RewritePath("~/page", false);
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Handles the URL Rewriting for the application
        /// </summary>
        /// <param name="context">Http context</param>
        public static void BeginRequest(HttpContext context)
        {
            try {
                string path = context.Request.Path.Substring(context.Request.ApplicationPath.Length > 1 ?
                                                             context.Request.ApplicationPath.Length : 0);

                string[] args = path.Split(new char[] { '/' }).Subset(1);

                if (args.Length > 0)
                {
                    int pos = 0;

                    // Ensure database
                    if (args[0] == "" && SysParam.GetByName("SITE_VERSION") == null)
                    {
                        context.Response.Redirect("~/manager", false);
                        context.Response.EndClean();
                    }

                    // Check for culture prefix
                    if (Cultures.ContainsKey(args[0]))
                    {
                        System.Threading.Thread.CurrentThread.CurrentCulture       =
                            System.Threading.Thread.CurrentThread.CurrentUICulture = Cultures[args[0]];
                        pos = 1;
                    }
                    else
                    {
                        var def = (GlobalizationSection)WebConfigurationManager.GetSection("system.web/globalization");
                        if (def != null && !String.IsNullOrWhiteSpace(def.Culture) && !def.Culture.StartsWith("auto:"))
                        {
                            System.Threading.Thread.CurrentThread.CurrentCulture       =
                                System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo(def.UICulture);
                        }
                    }

                    // Check for hostname extension. This feature can't be combined with culture prefixes
                    if (pos == 0)
                    {
                        var segments = context.Request.RawUrl.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
                        if (segments.Length > 0)
                        {
                            var hostExt = context.Request.Url.Host + "/" + segments[0];

                            if (HostNames.ContainsKey(hostExt))
                            {
                                RequestedSite = new ExtendedHostName()
                                {
                                    HostName  = context.Request.Url.Host,
                                    Extension = segments[0],
                                    SiteTree  = HostNames[hostExt]
                                };
                                if (segments[0] == args[0])
                                {
                                    pos = 1;

                                    // If this was the last argument, add an empty one
                                    if (args.Length == 1)
                                    {
                                        args = args.Concat(new string[] { "" }).ToArray();
                                    }
                                }
                            }
                        }
                    }

                    var handled = false;

                    // Find the correct request handler
                    foreach (var hr in Application.Current.Handlers)
                    {
                        if (hr.UrlPrefix.ToLower() == args[pos].ToLower())
                        {
                            if (hr.Id != "PERMALINK" || !Config.PrefixlessPermalinks)
                            {
                                // Don't execute permalink routing in passive mode
                                if ((hr.Id != "PERMALINK" && hr.Id != "STARTPAGE") || !Config.PassiveMode)
                                {
                                    // Execute the handler
                                    hr.Handler.HandleRequest(context, args.Subset(pos + 1));
                                    handled = true;
                                    break;
                                }
                            }
                        }
                    }

                    if (!handled && args[pos].ToLower() == "res.ashx")
                    {
                        Application.Current.Resources.HandleRequest(context, args.Subset(pos + 1));
                        handled = true;
                    }

                    // If no handler was found and we are using prefixless permalinks,
                    // route traffic to the permalink handler.
                    if (!Config.PassiveMode)
                    {
                        if (!handled && Config.PrefixlessPermalinks && args[pos].ToLower() != "manager" && String.IsNullOrEmpty(context.Request["permalink"]))
                        {
                            if (Permalink.GetByName(Config.SiteTreeNamespaceId, args[pos]) != null || Permalink.GetByName(Config.DefaultNamespaceId, args[pos]) != null)
                            {
                                var handler = Application.Current.Handlers["PERMALINK"];
                                handler.HandleRequest(context, args.Subset(pos));
                            }
                        }
                    }
                }
            } catch (ThreadAbortException) {
                // We simply swallow this exception as we don't want unhandled
                // exceptions flying around causing the app pool to die.
            } catch (Exception e) {
                // One catch to rule them all, and in the log file bind them.
                Application.Current.LogProvider.Error("WebPiranha.BeginRequest", "Unhandled exception", e);
                context.Response.StatusCode = 500;
                context.Response.EndClean();
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Handles the current request.
        /// </summary>
        /// <param name="context">The current context</param>
        /// <param name="draft">Whether to get the draft or not</param>
        /// <param name="args">Optional url arguments passed to the handler</param>
        protected void HandleRequest(HttpContext context, bool draft, params string[] args)
        {
            if (args != null && args.Length > 0)
            {
                Content content = null;
                int?    width = null, height = null;
                Guid?   id        = null;
                string  permalink = null;

                // Try to create guid from input
                try {
                    id = new Guid(args[0]);
                } catch {}

                // If if wasn't a guid, try to create permalink
                if (!id.HasValue)
                {
                    try {
                        permalink = GetPermalink(args[0], ref width, ref height);
                    } catch {}
                }

                try {
                    if (id.HasValue)
                    {
                        // Get content by id
                        content = Content.GetSingle(id.Value, draft);
                        if (content != null)
                        {
                            if (args.Length > 1)
                            {
                                try {
                                    width = Convert.ToInt32(args[1]);
                                } catch {}
                            }
                            if (args.Length > 2)
                            {
                                try {
                                    height = Convert.ToInt32(args[2]);
                                } catch {}
                            }
                        }
                    }
                    else if (!String.IsNullOrEmpty(permalink))
                    {
                        // Get content by permalink
                        var perm = Permalink.GetByName(Config.MediaNamespaceId, permalink);

                        if (perm != null)
                        {
                            content = Content.GetByPermalinkId(perm.Id);
                        }
                    }
                } catch {}

                // Since we don't handle viewing image drafts right now, don't execute the overhead
                // if (content.IsDraft && !Extend.ExtensionManager.Current.MediaProvider.ExistsDraft(content.Id))
                //	 content.IsDraft = false ;

                if (content != null)
                {
                    if (height.HasValue)
                    {
                        content.GetMedia(context, width, height);
                    }
                    content.GetMedia(context, width);
                }
                else
                {
                    context.Response.StatusCode = 404;
                }
            }
            else
            {
                context.Response.StatusCode = 500;
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Handles the URL Rewriting for the application
        /// </summary>
        /// <param name="context">Http context</param>
        public static void BeginRequest(HttpContext context)
        {
            try {
                string path = context.Request.Path.Substring(context.Request.ApplicationPath.Length > 1 ?
                                                             context.Request.ApplicationPath.Length : 0);

                string[] args = path.Split(new char[] { '/' }).Subset(1);

                if (args.Length > 0)
                {
                    int pos = 0;

                    // Ensure database
                    if (args[0] == "" && SysParam.GetByName("SITE_VERSION") == null)
                    {
                        context.Response.Redirect("~/manager", false);
                        context.Response.EndClean();
                    }

                    // Check for culture prefix
                    if (Cultures.ContainsKey(args[0]))
                    {
                        System.Threading.Thread.CurrentThread.CurrentCulture       =
                            System.Threading.Thread.CurrentThread.CurrentUICulture = Cultures[args[0]];
                        pos = 1;
                    }
                    else
                    {
                        var def = (GlobalizationSection)WebConfigurationManager.GetSection("system.web/globalization");
                        if (def != null)
                        {
                            System.Threading.Thread.CurrentThread.CurrentCulture       =
                                System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo(def.UICulture);
                        }
                    }

                    var handled = false;

                    // Find the correct request handler
                    foreach (var hr in Application.Current.Handlers)
                    {
                        if (hr.UrlPrefix.ToLower() == args[pos].ToLower())
                        {
                            if (hr.Id != "PERMALINK" || !PrefixlessPermalinks)
                            {
                                // Don't execute permalink routing in passive mode
                                if ((hr.Id != "PERMALINK" && hr.Id != "STARTPAGE") || !Config.PassiveMode)
                                {
                                    // Execute the handler
                                    hr.Handler.HandleRequest(context, args.Subset(pos + 1));
                                    handled = true;
                                    break;
                                }
                            }
                        }
                    }

                    if (!handled && args[pos].ToLower() == "res.ashx")
                    {
                        Application.Current.Resources.HandleRequest(context, args.Subset(pos + 1));
                        handled = true;
                    }

                    // If no handler was found and we are using prefixless permalinks,
                    // route traffic to the permalink handler.
                    if (!Config.PassiveMode)
                    {
                        if (!handled && PrefixlessPermalinks && args[0].ToLower() != "manager" && String.IsNullOrEmpty(context.Request["permalink"]))
                        {
                            if (Permalink.GetByName(Config.SiteTreeNamespaceId, args[0]) != null || Permalink.GetByName(Config.DefaultNamespaceId, args[0]) != null)
                            {
                                var handler = new PermalinkHandler();
                                handler.HandleRequest(context, args);
                            }
                        }
                    }
                }
            } catch (ThreadAbortException) {
                // We simply swallow this exception as we don't want unhandled
                // exceptions flying around causing the app pool to die.
            } catch (Exception e) {
                // One catch to rule them all, and in the log file bind them.
                Application.Current.LogProvider.Error("WebPiranha.BeginRequest", "Unhandled exception", e);
                context.Response.StatusCode = 500;
                context.Response.EndClean();
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Handles the current request.
        /// </summary>
        /// <param name="context">The current context</param>
        /// <param name="draft">Whether to view the draft</param>
        /// <param name="args">Optional url arguments passed to the handler</param>
        protected virtual void HandleRequest(HttpContext context, bool draft, params string[] args)
        {
            if (args != null && args.Length > 0)
            {
                Permalink perm     = null;
                int       segments = 0;
                // Accept permalinks with '/' in them
                for (int n = 0; n < args.Length; n++)
                {
                    perm     = Permalink.GetByName(Config.SiteTreeNamespaceId, args.Subset(0, args.Length - n).Implode("/"));
                    segments = args.Length - n;
                    if (perm != null)
                    {
                        break;
                    }
                }

                if (perm != null)
                {
                    if (perm.Type == Permalink.PermalinkType.PAGE)
                    {
                        Page page = Page.GetByPermalinkId(perm.Id, draft);

                        if (page != null)
                        {
                            if (!String.IsNullOrEmpty(page.Redirect))
                            {
                                if (page.Redirect.StartsWith("http://"))
                                {
                                    context.Response.Redirect(page.Redirect);
                                }
                                else
                                {
                                    context.Response.Redirect(page.Redirect);
                                }
                            }
                            else if (!String.IsNullOrEmpty(page.Controller))
                            {
                                if (page.Controller.StartsWith("~/"))
                                {
                                    context.RewritePath(page.Controller + "/" + args.Subset(segments).Implode("/") + "?permalink=" + perm.Name, false);
                                }
                                else
                                {
                                    var urldata = "";
                                    if (Config.DisableMethodBinding)
                                    {
                                        urldata = args.Implode("/");
                                    }
                                    else
                                    {
                                        urldata = args.Subset(segments).Implode("/");
                                    }

                                    context.RewritePath("~/templates/" + page.Controller + "/" + urldata + "?permalink=" + perm.Name +
                                                        (draft ? "&draft=true" : "") + GetCultureParam(context, true), false);
                                }
                            }
                            else
                            {
                                var urldata = "";
                                if (Config.DisableMethodBinding)
                                {
                                    urldata = args.Implode("/");
                                }
                                else
                                {
                                    urldata = args.Subset(segments).Implode("/");
                                }

                                context.RewritePath("~/page/" + urldata + "?permalink=" + perm.Name +
                                                    (draft ? "&draft=true" : "") + GetCultureParam(context, true), false);
                            }
                        }
                        else
                        {
                            context.Response.StatusCode = 404;
                        }
                    }
                    else if (perm.Type == Permalink.PermalinkType.POST)
                    {
                        Post post = Post.GetByPermalinkId(perm.Id, draft);

                        // Get rid of permalink from urldata if we're not trying to be backwards compatible
                        if (!Config.DisableMethodBinding)
                        {
                            args = args.Subset(segments);
                        }

                        if (post != null)
                        {
                            if (!String.IsNullOrEmpty(post.Controller))
                            {
                                context.RewritePath("~/templates/" + post.Controller + "/" + args.Implode("/") + "?permalink=" + perm.Name +
                                                    (draft ? "&draft=true" : "") + GetCultureParam(context, true), false);
                            }
                            else
                            {
                                context.RewritePath("~/post/" + args.Implode("/") + "?permalink=" + perm.Name +
                                                    (draft ? "&draft=true" : "") + GetCultureParam(context, true), false);
                            }
                        }
                        else
                        {
                            context.Response.StatusCode = 404;
                        }
                    }
                }
                else
                {
                    context.Response.StatusCode = 404;
                }
            }
            else
            {
                //
                // Rewrite to current startpage
                //
                Page page = Page.GetStartpage();

                if (!String.IsNullOrEmpty(page.Controller))
                {
                    context.RewritePath("~/templates/" + page.Controller, false);
                }
                else
                {
                    context.RewritePath("~/page", false);
                }
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Handles the URL Rewriting for the application
        /// </summary>
        /// <param name="context">Http context</param>
        public static void BeginRequest(HttpContext context)
        {
            string path = context.Request.Path.Substring(context.Request.ApplicationPath.Length > 1 ?
                                                         context.Request.ApplicationPath.Length : 0);

            string[] args = path.Split(new char[] { '/' }).Subset(1);

            if (args.Length > 0)
            {
                int pos = 0;

                // Ensure database
                if (args[0] == "" && SysParam.GetByName("SITE_VERSION") == null)
                {
                    context.Response.Redirect("~/manager");
                }

                // Check for culture prefix
                if (Cultures.ContainsKey(args[0]))
                {
                    System.Threading.Thread.CurrentThread.CurrentUICulture = Cultures[args[0]];
                    pos = 1;
                }
                else
                {
                    var def = (GlobalizationSection)WebConfigurationManager.GetSection("system.web/globalization");
                    if (def != null)
                    {
                        System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo(def.UICulture);
                    }
                }

                var handled = false;

                // Find the correct request handler
                foreach (RequestHandlerRegistration hr in Handlers.Values)
                {
                    if (hr.UrlPrefix.ToLower() == args[pos].ToLower())
                    {
                        if (hr.Id != "PERMALINK" || !PrefixlessPermalinks)
                        {
                            // Execute the handler
                            hr.Handler.HandleRequest(context, args.Subset(pos + 1));
                            handled = false;
                            break;
                        }
                    }
                }

                // If no handler was found and we are using prefixless permalinks,
                // route traffic to the permalink handler.
                if (!handled && PrefixlessPermalinks && args[0].ToLower() != "manager")
                {
                    if (Permalink.GetByName(Config.SiteTreeNamespaceId, args[0]) != null)
                    {
                        var handler = new PermalinkHandler();
                        handler.HandleRequest(context, args);
                    }
                }
            }
        }