Ejemplo n.º 1
0
 protected virtual void Application_BeginRequest(object o, EventArgs e)
 {
     //mono 下编码可能会有问题
     if (FwCtx.Mono())
     {
         Response.Charset = "utf-8";
     }
 }
Ejemplo n.º 2
0
        private void RegisterRoute()
        {
            RouteCollection routes        = RouteTable.Routes;
            IRouteHandler   pluginHandler = new PluginRouteHandler();

            routes.Add("plugin_do", new Route("{plugin}.do/{*path}", pluginHandler));
            routes.Add("plugin_pl", new Route("{plugin}.pl/{*path}", pluginHandler));
            routes.Add("plugin_aspx", new Route("{plugin}.pl.aspx/{*path}", pluginHandler));

            if (FwCtx.Mono())
            {
                routes.Add("plugin_mono_do", new Route("{plugin}.do", pluginHandler));
                routes.Add("plugin_mono_pl", new Route("{plugin}.pl", pluginHandler));
                routes.Add("plugin_mono_aspx", new Route("{plugin}.pl.aspx", pluginHandler));
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 注册插件路由
        /// </summary>
        /// <param name="aliasName">别名</param>
        /// <param name="workIndent">插件标识</param>
        private static void MapExtendPluginRoute(string aliasName, string workIndent)
        {
            RouteValueDictionary routeValue = new RouteValueDictionary();

            routeValue.Add("extend", workIndent);

            RouteTable.Routes.Add("extend_sh_" + aliasName,
                                  new Route(aliasName + "/{*path}",
                                            routeValue,
                                            new PluginExtendRouteHandler()));

            if (FwCtx.Mono())
            {
                RouteTable.Routes.Add("mono_extend_sh_" + aliasName,
                                      new Route(aliasName,
                                                routeValue,
                                                new PluginExtendRouteHandler()));
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// 设置目录隐藏
 /// </summary>
 /// <param name="dirPath"></param>
 public static void SetDirHidden(string dirPath)
 {
     if (!FwCtx.Mono())
     {
         DirectoryInfo dir = new DirectoryInfo(String.Format("{0}{1}", AppDomain.CurrentDomain.BaseDirectory, dirPath));
         if (!dir.Exists)
         {
             Directory.CreateDirectory(dir.FullName).Create();
             dir.Attributes = dir.Attributes & FileAttributes.Hidden;
         }
         else
         {
             if ((dir.Attributes & FileAttributes.Hidden) != FileAttributes.ReadOnly)
             {
                 dir.Attributes = dir.Attributes & FileAttributes.Hidden;
             }
         }
     }
 }
Ejemplo n.º 5
0
 /// <summary>
 /// 设置目录隐藏
 /// </summary>
 /// <param name="dirPath"></param>
 public static void SetDirHidden(string dirPath)
 {
     if (!FwCtx.Mono())
     {
         DirectoryInfo dir = new DirectoryInfo($"{EnvUtil.GetBaseDirectory()}/{dirPath}");
         if (!dir.Exists)
         {
             Directory.CreateDirectory(dir.FullName).Create();
             dir.Attributes = dir.Attributes & FileAttributes.Hidden;
         }
         else
         {
             if ((dir.Attributes & FileAttributes.Hidden) != FileAttributes.ReadOnly)
             {
                 dir.Attributes = dir.Attributes & FileAttributes.Hidden;
             }
         }
     }
 }
Ejemplo n.º 6
0
        /// <summary>
        /// 注册插件路由
        /// </summary>
        /// <param name="aliasName">别名</param>
        /// <param name="workIndent">插件标识</param>
        private static void MapPluginRoute(string aliasName, string workIndent)
        {
            RouteValueDictionary routeValue = new RouteValueDictionary();

            routeValue.Add("plugin", workIndent);

            String routeKey = "plugin_sh_" + aliasName;

            RouteTable.Routes.Add(routeKey,
                                  new Route(aliasName + "/{*path}",
                                            routeValue,
                                            new PluginRouteHandler()));

            if (FwCtx.Mono())
            {
                String monoRouteKey = "mono_plugin_sh_" + aliasName;
                RouteTable.Routes.Add(monoRouteKey,
                                      new Route(aliasName,
                                                routeValue,
                                                new PluginRouteHandler()));
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 注册路由
        /// </summary>
        /// <param name="routes">路由集合</param>
        /// <param name="cmsHandleType"></param>
        private static void RegisterInstalledCmsRoutes(RouteCollection routes, Type cmsHandleType)
        {
            //路由前缀,前缀+虚拟路径
            //string routePrefix = (String.IsNullOrEmpty(prefix) ? "" : prefix + "/")
            //    + (String.IsNullOrEmpty(Settings.SYS_VIRTHPATH) ? String.Empty:Settings.SYS_VIRTHPATH + "/");

            // string urlPrefix = "/" + routePrefix;
            string urlPrefix = String.Empty, routePrefix = String.Empty;

            //Cms 控制器名称,如果继承默认的Handler,则使用默认的Handler
            string cmsControllerName = Regex.Replace(cmsHandleType.Name, "controller$", String.Empty, RegexOptions.IgnoreCase);

            //MVC路由规则词典
            IDictionary <UrlRulePageKeys, string[]> dict = new Dictionary <UrlRulePageKeys, string[]>();

            dict.Add(UrlRulePageKeys.Common, new string[] { "cms_common", routePrefix + "{0}", urlPrefix + "{0}" });

            dict.Add(UrlRulePageKeys.Search, new string[] { "cms_search", routePrefix + "search", urlPrefix + "search?w={0}&c={1}" });
            dict.Add(UrlRulePageKeys.SearchPager, new string[] { null, null, urlPrefix + "search?w={0}&c={1}&p={2}" });

            dict.Add(UrlRulePageKeys.Tag, new string[] { "cms_tag", routePrefix + "tag", urlPrefix + "tag?t={0}" });
            dict.Add(UrlRulePageKeys.TagPager, new string[] { null, null, urlPrefix + "tag?t={0}&p={1}" });

            dict.Add(UrlRulePageKeys.Category, new string[] { "cms_category", routePrefix + "{*allcate}", urlPrefix + "{0}/" });
            dict.Add(UrlRulePageKeys.CategoryPager, new string[] { null, null, urlPrefix + "{0}/p{1}.html" });

            dict.Add(UrlRulePageKeys.Archive, new string[] { "cms_archive", routePrefix + "{*allhtml}", urlPrefix + "{0}/{1}.html" });
            dict.Add(UrlRulePageKeys.SinglePage, new string[] { null, null, urlPrefix + "{0}.html" });

            //注册插件路由
            //Cms.Plugins.Extends.MapRoutes(routes);

            //Cms.Plugins.MapRoutes(routes);


            #region 系统路由


            //忽略静态目录
            routes.IgnoreRoute("{staticdir}/{*pathInfo}", new { staticdir = "^(uploads|resources|content|static|plugins|libs|scripts|images|style|themes)$" });

            //tempaltes路由处理(忽略静态文件)
            routes.IgnoreRoute("templates/{*pathInfo}", new { pathInfo = "^(.+?)\\.(jpg|jpeg|css|js|json|xml|gif|png|bmp)$" });
            routes.MapRoute("tpl_catchall", "templates/{*catchall}", new { controller = cmsControllerName, action = "Disallow" });

            //安装路由
            routes.Add("install_route", new Route("install/process", new CmsInstallHandler()));

            //管理后台
            routes.Add("administrator_route", new Route(Settings.SYS_ADMIN_TAG, new CmsManagerRouteHandler()));


            //兼容以前插件
            IRouteHandler pluginHandler = new PluginRouteHandler();
            routes.Add("plugin_sh_pl", new Route("{plugin}.sh/{*path}", pluginHandler));
            routes.Add("plugin_sh_aspx", new Route("{plugin}.sh.aspx/{*path}", pluginHandler));

            if (FwCtx.Mono())
            {
                routes.Add("plugin_mono_sh_pl", new Route("{plugin}.sh", pluginHandler));
                routes.Add("plugin_mono_sh_aspx", new Route("{plugin}.sh.aspx", pluginHandler));
            }

            //WebAPI接口
            //routes.Add("webapi", new Route("webapi/{*path}", new WebApiRouteHandler()));
            routes.Add("webapi_router", new Route("webapi", new WebApiRouteHandler()));
            routes.Add("webapi_subsite_router", new Route("{site}/webapi", new WebApiRouteHandler()));

            //支付
            //routes.Add(new Route(routePrefix + "netpay", new CmsNetpayHandler()));



            //搜索档案
            routes.MapRoute(
                dict[UrlRulePageKeys.Search][0] + "_site", "{site}/" + dict[UrlRulePageKeys.Search][1],
                new { controller = cmsControllerName, action = "Search", p = 1 }
                );


            //搜索档案
            routes.MapRoute(
                dict[UrlRulePageKeys.Search][0], dict[UrlRulePageKeys.Search][1],
                new { controller = cmsControllerName, action = "Search", p = 1 }
                );

            //标签档案
            routes.MapRoute(
                dict[UrlRulePageKeys.Tag][0], dict[UrlRulePageKeys.Tag][1],
                new { controller = cmsControllerName, action = "Tag", p = 1 }
                );



            //多站点
            //if (jr.MultSiteVersion)
            //{
            //默认路由
            //    routes.MapRoute(
            //        "IndexPage",
            //        "{sitedir}",
            //        new { controller = cmsControllerName, action = "Index", id = UrlParameter.Optional }
            //    );
            //}


            //栏目档案列表
            routes.MapRoute(
                dict[UrlRulePageKeys.Category][0], dict[UrlRulePageKeys.Category][1],
                new { controller = cmsControllerName, action = "Category", page = 1 }, new { allcate = "^(?!" +
                                                                                                       CmsVariables.DEFAULT_CONTROLLER_NAME + ")((.+?)/(p\\d+\\.html)?|([^/]+/)*[^\\.]+)$" }
                );

            #region Route For Mono


            //if (isMono)
            //{

            /*************Category Only for mono *******************/

            //包含前缀情况下对Mono平台的/{lang}/进行支持

            /*
             *  if (routePrefix != "")
             *  {
             *      routes.MapRoute(
             *      "cms_mono_index",
             *      routePrefix,
             *      new { controller = cmsControllerName, action = "Index" }
             *  );
             *  }*/
            /**********************************************/
            //}


            #endregion

            //显示档案
            routes.MapRoute(
                dict[UrlRulePageKeys.Archive][0], dict[UrlRulePageKeys.Archive][1],
                new { controller = cmsControllerName, action = "Archive" }, new { allhtml = "^(.+?).html$" }
                );

            //默认路由
            routes.MapRoute(
                "Default",                                                                                   // Route name
                routePrefix + "{controller}/{action}/{id}",                                                  // URL with parameters
                new { controller = cmsControllerName, action = "Index", id = UrlParameter.Optional }         // Parameter defaults
                );


            routes.MapRoute("allpath", "{*path}", new { controller = cmsControllerName, action = "NotFound" });

            #endregion

            #region 设置地址

            IDictionary <UrlRulePageKeys, string> urlDict = new Dictionary <UrlRulePageKeys, string>();
            foreach (KeyValuePair <UrlRulePageKeys, string[]> p in dict)
            {
                urlDict.Add(p.Key, p.Value[2]);
            }

            //设置地址
            TemplateUrlRule.SetUrl(UrlRuleType.Mvc, urlDict);

            //使用MVC
            TemplateUrlRule.SetRule(UrlRuleType.Mvc);

            #endregion
        }