Exemplo n.º 1
0
        /// <summary>
        /// 重写 URL 路径
        /// </summary>
        /// <param name="uri">用户原始请求信息</param>
        /// <returns>重定向路径, 如果为空则不处理</returns>
        private string ReWriteURLPath(Uri uri)
        {
            BLL.WebSite bllsite   = new BLL.WebSite();
            string      site_name = bllsite.MatchSiteName(uri.AbsolutePath);

            Model.WebSite modelsite = bllsite.GetModel(site_name);
            if (CheckData.IsObjectNull(modelsite))
            {
                return(string.Empty);
            }

            BLL.URLReWriter   bllurl   = new BLL.URLReWriter(modelsite);
            Model.URLReWriter modelurl = bllurl.GetItem_RequestURI(uri.AbsolutePath);

            if (CheckData.IsObjectNull(modelurl))
            {
                string resource_file     = bllurl.GetResourceFilePath(uri.AbsolutePath, bllsite);
                string abs_resource_file = PathHelp.ToAbsolute(resource_file);
                if (File.Exists(abs_resource_file))
                {
                    return(resource_file);
                }

                // 当得到的对象 为空的时候,证明没有此数据内容,当然也就不用生成了
                return(string.Empty);
            }

            FileInfo FItemp = new FileInfo(bllurl.GetFilePath_Templet(modelurl));

            if (!FItemp.Exists)
            {
                // 模板文件都不存在的话,就不用生成了
                return(string.Empty);
            }

            SystemConfig sys_config = GlobalSystemService.GetInstance().Config.Get <SystemConfig>();
            FileInfo     FItarget   = new FileInfo(bllurl.GetFilePath_Target(modelurl));

            if (sys_config.Is_DeBug || !FItarget.Exists || FItemp.LastWriteTime > FItarget.LastWriteTime)
            {
                // 生成模板
                HtmlToAspx        hta = new HtmlToAspx();
                HtmlToAspx.Params par = hta.ParamsMerge(modelurl, FItemp, FItarget);
                hta.Generate(par);
            }

            return(bllurl.HTTPRedirectPath(uri, modelurl));
        }
Exemplo n.º 2
0
        /// <summary>
        /// 第一个事件执行
        /// </summary>
        private void BeginRequest(object sender, EventArgs e)
        {
            HttpContext context = ((HttpApplication)sender).Context;

            // 获得请求页面路径页面(含目录)
            string request_path = context.Request.Path.ToLower();

            if (request_path == @"/")
            {
                context.Response.Redirect(@"index.aspx");
                return;
            }

            // 检查请求的文件是否存在 如:存在,跳出,没必要做任何处理
            string request_absfilepath = PathHelp.ToAbsolute(request_path);

            request_absfilepath = ConvertTool.ToString(request_absfilepath);
            if (File.Exists(request_absfilepath))
            {
                return;
            }

            // 执行生成执行页面内容
            string redirect_path = ReWriteURLPath(context.Request.Url);

            if (!CheckData.IsStringNull(redirect_path))
            {
                SystemLog log = new SystemLog()
                {
                    Type     = SystemLog.LogType.Record,
                    Position = @"YTS.Web.UI.HttpModule.BeginRequest",
                    Message  = string.Format("new redirect path: {0}", redirect_path),
                };
                log.Write();

                // HTTP请求重写路径
                context.RewritePath(redirect_path);
            }
        }
Exemplo n.º 3
0
 public CaseModel Func_ToAbsolute()
 {
     return(new CaseModel()
     {
         NameSign = @"转为绝对路径",
         ExeEvent = () => {
             string basic_dir = AppDomain.CurrentDomain.BaseDirectory;
             KeyString[] paths = new KeyString[] {
                 new KeyString()
                 {
                     Key = null,
                     Value = string.Empty,
                 },
                 new KeyString()
                 {
                     Key = string.Empty,
                     Value = string.Empty,
                 },
                 new KeyString()
                 {
                     Key = "/",
                     Value = basic_dir,
                 },
                 new KeyString()
                 {
                     Key = "/test/wlif/jiw/name.txt",
                     Value = basic_dir + "test\\wlif\\jiw\\name.txt",
                 },
                 new KeyString()
                 {
                     Key = "//",
                     Value = basic_dir,
                 },
                 new KeyString()
                 {
                     Key = "/test//wlif/jiw/name.txt",
                     Value = basic_dir + "test\\wlif\\jiw\\name.txt",
                 },
                 new KeyString()
                 {
                     Key = "/test//wlif//jiw////name.txt",
                     Value = basic_dir + "test\\wlif\\jiw\\name.txt",
                 },
                 new KeyString()
                 {
                     Key = basic_dir + "test\\wlif\\jiw\\name.txt",
                     Value = basic_dir + "test\\wlif\\jiw\\name.txt",
                 },
                 new KeyString()
                 {
                     Key = "sdfaw/efae/fee/",
                     Value = basic_dir + "sdfaw\\efae\\fee\\",
                 },
                 new KeyString()
                 {
                     Key = "ttt",
                     Value = basic_dir + "ttt",
                 },
                 new KeyString()
                 {
                     Key = "qqq/",
                     Value = basic_dir + "qqq\\",
                 },
                 new KeyString()
                 {
                     Key = "C:\\",
                     Value = "C:\\",
                 },
                 new KeyString()
                 {
                     Key = "C://",
                     Value = "C:\\",
                 },
             };
             foreach (KeyString item in paths)
             {
                 string abs_path = PathHelp.ToAbsolute(item.Key);
                 if (!abs_path.Equals(item.Value))
                 {
                     Console.WriteLine("  item.Key: {0}", item.Key);
                     Console.WriteLine("  abs_path: {0}", abs_path);
                     Console.WriteLine("item.Value: {0}", item.Value);
                     return false;
                 }
             }
             return true;
         },
     });
 }