Esempio n. 1
0
        protected virtual void RegisterRoutes(RouteCollection routes, HttpApplication application)
        {
            routes.Add("SnODataRoute", new Route("odata.svc/{*path}", new ODataRouteHandler()));
            routes.Add("SnWopiRoute", new Route("wopi/{*path}", new WopiRouteHandler()));

            var resourceHandler = new ResourceHandler();

            routes.Add("SnResourceRoute", new Route(ResourceHandler.UrlPart + "/{*anything}", new ProxyingRouteHandler(ctx => resourceHandler)));
            routes.Add("SnBinaryRoute", new Route(BinaryHandlerBase.UrlPart + "/{contentId}/{propertyName}/{maxAge}/{width}/{height}", new RouteValueDictionary(new Dictionary <string, object>()
            {
                { "propertyName", "Binary" },
                { "maxAge", "0" },
                { "width", "0" },
                { "height", "0" },
            }), new ProxyingRouteHandler(ctx =>
            {
                var contentIdStr = ctx.RouteData.Values["contentId"] as string;
                int contentId    = 0;
                if (!string.IsNullOrEmpty(contentIdStr) && !int.TryParse(contentIdStr, out contentId))
                {
                    return(null);
                }

                var propertyName = ctx.RouteData.Values["propertyName"] as string ?? "Binary";

                var node = Node.LoadNode(contentId);

                if (node != null && propertyName != null && node.HasProperty(propertyName))
                {
                    var maxAgeStr = ctx.RouteData.Values["maxAge"] as string;
                    int maxAge;
                    int.TryParse(maxAgeStr, out maxAge);

                    var widthStr = ctx.RouteData.Values["width"] as string;
                    int width;
                    int.TryParse(widthStr, out width);

                    var heightStr = ctx.RouteData.Values["height"] as string;
                    int height;
                    int.TryParse(heightStr, out height);

                    var handler = new BinaryHandlerBase(node, propertyName, maxAge == 0 ? null : (TimeSpan?)TimeSpan.FromDays(maxAge), width == 0 ? null : (int?)width, height == 0 ? null : (int?)height);
                    return(handler);
                }

                return(null);
            })));
        }
Esempio n. 2
0
        protected virtual void RegisterRoutes(RouteCollection routes, HttpApplication application)
        {
            var engine = (WebFormViewEngine)ViewEngines.Engines[0];

            engine.ViewLocationFormats = new[] {
                "~/root/MvcViews/{1}/{0}.aspx",
                "~/root/MvcViews/{1}/{0}.ascx",
                "~/root/MvcViews/Shared/{0}.aspx",
                "~/root/MvcViews/Shared/{0}.ascx"
            };

            engine.MasterLocationFormats = new[] {
                "~/root/MvcViews/{1}/{0}.master",
                "~/root/MvcViews/Shared/{0}.master"
            };

            engine.PartialViewLocationFormats = engine.ViewLocationFormats;

            routes.MapRoute(
                "Default",                         // Route name
                "{controller}.mvc/{action}/{pid}", // URL with parameters
                new { controller = "Home", action = "Index", pid = "" } // Parameter defaults
                );

            var bundleHandler   = new BundleHandler();
            var resourceHandler = new ResourceHandler();

            routes.Add("SnBundleRoute", new Route(BundleHandler.UrlPart + "/{*anything}", new ProxyingRouteHandler(ctx => bundleHandler)));
            routes.Add("SnResourceRoute", new Route(ResourceHandler.UrlPart + "/{*anything}", new ProxyingRouteHandler(ctx => resourceHandler)));
            routes.Add("SnBinaryRoute", new Route(BinaryHandlerBase.UrlPart + "/{contentId}/{propertyName}/{maxAge}/{width}/{height}", new RouteValueDictionary(new Dictionary <string, object>()
            {
                { "propertyName", "Binary" },
                { "maxAge", "0" },
                { "width", "0" },
                { "height", "0" },
            }), new ProxyingRouteHandler(ctx =>
            {
                var contentIdStr = ctx.RouteData.Values["contentId"] as string;
                int contentId    = 0;
                if (!string.IsNullOrEmpty(contentIdStr) && !int.TryParse(contentIdStr, out contentId))
                {
                    return(null);
                }

                var propertyName = ctx.RouteData.Values["propertyName"] as string ?? "Binary";

                var node = Node.LoadNode(contentId);

                if (node != null && propertyName != null && node.HasProperty(propertyName))
                {
                    var maxAgeStr = ctx.RouteData.Values["maxAge"] as string;
                    int maxAge;
                    int.TryParse(maxAgeStr, out maxAge);

                    var widthStr = ctx.RouteData.Values["width"] as string;
                    int width;
                    int.TryParse(widthStr, out width);

                    var heightStr = ctx.RouteData.Values["height"] as string;
                    int height;
                    int.TryParse(heightStr, out height);

                    var handler = new BinaryHandlerBase(node, propertyName, maxAge == 0 ? null : (TimeSpan?)TimeSpan.FromDays(maxAge), width == 0 ? null : (int?)width, height == 0 ? null : (int?)height);
                    return(handler);
                }

                return(null);
            })));
        }