Пример #1
0
 public void TestGetSiteControllerNamesPattern()
 {
     Web.Write(MvcUtil.GetSiteControllerNamesPattern());
     Assert.Pass();
 }
Пример #2
0
        public static void RegisterRoutes(RouteCollection routes)
        {
            string[] siteNamespace = new string[] { "Site.Controllers" };

            // when set to TRUE this means that if a file exists and also a route matches, the routes win
            routes.RouteExistingFiles = false;

            routes.MapRoute("Robots", "robots.txt", new { controller = "UrlRedirect", action = "Robotos" });

            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
            //routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
            routes.IgnoreRoute("{*staticfiles}", new { staticfiles = @".*\.(css|js|gif|jpg|ico|txt)" });          // removed png for dynamicimages
            //routes.IgnoreRoute("{*allaspx}", new {allaspx=@".*\.aspx(/.*)?"});
            //routes.IgnoreRoute("{*allasp}", new {allasp=@".*\.asp"});        // leave classic asp
            //routes.IgnoreRoute("");                // don't take over the root

            // errors
            routes.MapRoute("LogJavascriptError", "Error/LogJavascriptError", new { controller = "Error", action = "LogJavascriptError" });
            routes.MapRoute("FixError", "Error/FixError", new { controller = "Error", action = "FixError" });
            if (Util.GetSettingBool("404GoesToHomepage", false))
            {
                routes.MapRoute("errorNotFound", "Error/NotFound", new { controller = "Home", action = "NotFound" });
                routes.MapRoute("error404", "Error/404", new { controller = "Home", action = "NotFound" });
            }
            else
            {
                routes.MapRoute("errorNotFound", "Error/NotFound", new { controller = "Error", action = "NotFound" });
                routes.MapRoute("error404", "Error/404", new { controller = "Error", action = "NotFound" });
            }
            routes.MapRoute("error", "Error/{errorPage}", new { controller = "Error", action = "ShowErrorPage" });
            routes.MapRoute("trackingGif", "Track/{guid}", new { controller = "Common", action = "TrackingGif" });
            // images
            routes.MapRoute("RenderDynamicImage", "i/{id}_{version}/{crunched_title}.png", new { controller = "Images", action = "RenderDynamicImage" });

            // ----------------------

            // home
            routes.MapRoute("home", "", new { controller = "Home", action = "Index" });
            routes.MapRoute("default.aspx", "default.aspx", new { controller = "Home", action = "Index" });

            // ----------------------

            // document downloads
            // root categories, must be assigned to a page with a template of 'documentrepository'
            routes.MapRoute("documentrepository", "DocumentRepository", new { controller = "DocumentCategory", action = "ByPageID" });

            // all other sub categories and documents
            routes.MapRoute("documentcategory", "DocumentCategory/{enccategoryid}", new { controller = "DocumentCategory", action = "ByCategoryID" });
            routes.MapRoute("downloaddocument", "DownloadDocument/{encryptedID}", new { controller = "Download", action = "DownloadDocument" });

            // search
            routes.MapRoute("search", "Search", new { controller = "Search", action = "Search" });

            // XML Sitemap
            routes.MapRoute("XMLSitemap", "XMLSitemap", new { controller = "XML", action = "GetSitemapXML" });

            routes.MapRoute(
                "pageid",                                                 // Route name
                "Page/{id}/{crunched_title}",                             // URL with parameters
                new { controller = "StandardPage", action = "ByPageID" }, // match pattern
                new { id = @"\d+" }                                       // Parameter defaults
                );

            //pages
            routes.MapRoute("page", "Page/{*urlRewriteTitle}", new { controller = "StandardPage", action = "Index" });

            // standard beweb route
            routes.MapRoute(
                "BewebModels",                                                             // Route name
                "{controller}/{id}/{crunched_title}",                                      // URL with parameters
                new { action = "Index" },                                                  // Parameter defaults
                new { controller = MvcUtil.GetSiteControllerNamesPattern(), id = @"\d+" }, // match pattern
                siteNamespace                                                              // namespaces
                );

            // standard MVC route
            routes.MapRoute(
                "Default",                                                                 // Route name
                "{controller}/{action}/{id}",                                              // URL with parameters
                new { controller = "Home", action = "Index", id = UrlParameter.Optional }, // Parameter defaults
                new { controller = MvcUtil.GetSiteControllerNamesPattern() },
                siteNamespace                                                              // namespaces
                );

            // note this will take precedence over the UrlRedirectController below for any single word path (eg "/whatever")
            // good to use for small sites where UrlRedirectController is not used
            //routes.MapRoute("pagecode", "{pagecode}", new {controller = "StandardPage", action = "ByPageCode"});

            routes.MapRoute("catchall", "{*incomingUrl}", new { controller = "UrlRedirect", action = "CantBeRouted" }, siteNamespace);
        }