コード例 #1
0
ファイル: SecondRoute.cs プロジェクト: linrb/CMS-Source-code
    //重写该方法返回数据给Handler
    public override RouteData GetRouteData(HttpContextBase httpContext)
    {
        string           domain = httpContext.Request.Url.Host;
        string           path   = httpContext.Request.Path;
        RouteData        data   = null;//绑定Handler,这里完成后交给Handler
        M_IDC_DomainList model  = RouteHelper.GetModelByDomain(domain);

        if (RouteHelper.RouteDT == null || RouteHelper.RouteDT.Rows.Count < 1 || model == null)
        {
            new PageRouteHandler("~" + httpContext.Request.FilePath);
        }
        else
        {
            switch (model.SType)
            {
            case 1:    //directory
                #region 后台目录指向
            {
                data = new RouteData(this, RouteHandler);
                //用户访问的路径
                string filepath = httpContext.Request.FilePath.Equals("/") ? "default" : httpContext.Request.FilePath.TrimStart('/');
                filepath = filepath.Split('.')[0];        //不保留路径
                //替换占位符为实际文件路径(/test/test.aspx)
                model.Url = model.Url.Replace("*", filepath);
                //将实际访问的Url写入
                data.Values["url"] = model.Url;
                PushParam(data, model.Url);
                break;
            }

                #endregion
            case 2:    //Wix,  mydomain.z01.com/page
            {
                data = new RouteData(this, RouteHandler);
                //string mydomain = domain.Split('.')[0];
                string url = "/Design/PreView.aspx";        //domain=mydomain&page=page
                if (string.IsNullOrEmpty(path) || path.Equals("/"))
                {
                    path = "/index";
                }
                data.Values["url"] = url;
                PushParam(data, url + "?domain=" + domain + "&path=" + path);
            }
            break;
            }
        }
        return(data);
    }