コード例 #1
0
        /// <summary>
        /// 重写Url
        /// </summary>
        /// <param name="sender">事件的源</param>
        /// <param name="e">包含事件数据的 EventArgs</param>
        private void ReUrl_BeginRequest(object sender, EventArgs e)
        {
            HttpContext context     = ((HttpApplication)sender).Context;
            string      aspxPath    = "aspx";                                                                     //站点aspx文件目录
            string      requestPath = context.Request.Path.ToLower();                                             //获得当前页面,包含目录
            string      requestPage = requestPath.Substring(requestPath.LastIndexOf("/"));                        //获得当前页面,不包含目录

            DtCms.Model.WebSet SiteConfig = new DtCms.BLL.WebSet().loadConfig(Utils.GetXmlMapPath("Configpath")); //获得站点配置信息
            //排除不需要URL重写的目录
            bool   isRewritePath  = true;
            string notRewritePath = SiteConfig.WebManagePath + "|Aspx|Css|Images|Js|KindEditor|Templates|Tools|UpLoadFiles|XmlConfig"; //排除的目录列表

            string[] arrNotRewritePath = notRewritePath.Split('|');
            foreach (string str in arrNotRewritePath)
            {
                if (requestPath.StartsWith(SiteConfig.WebPath + str.ToLower() + "/"))
                {
                    isRewritePath = false;
                }
            }

            //================当启用伪地址时==================
            if (SiteConfig.IsUrlRewrite == 1 && isRewritePath)
            {
                foreach (SiteUrls.URLRewrite url in SiteUrls.GetSiteUrls().Urls)
                {
                    if (Regex.IsMatch(requestPath, SiteConfig.WebPath.TrimEnd('/') + url.Pattern, RegexOptions.None | RegexOptions.IgnoreCase))
                    {
                        string newUrl = Regex.Replace(requestPath, SiteConfig.WebPath.TrimEnd('/') + url.Pattern, url.QueryString, RegexOptions.None | RegexOptions.IgnoreCase);
                        context.RewritePath(SiteConfig.WebPath + aspxPath + url.Page, string.Empty, newUrl);
                        return;
                    }
                }
            }

            //==============当不启用伪地址重写时==============
            //验证是否是aspx文件
            bool isAspxFile = false;

            if (requestPath.LastIndexOf(".") >= 0)
            {
                if (requestPath.Substring(requestPath.LastIndexOf(".")) == ".aspx")
                {
                    isAspxFile = true;
                }
            }
            //以下将前台页面映射到Aspx目录下
            if (isRewritePath && isAspxFile)
            {
                context.RewritePath(SiteConfig.WebPath + aspxPath + requestPage);
                return;
            }
        }
コード例 #2
0
        /// <summary>
        /// 过滤SQL注入危险字符
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void KillSqlFilter(object sender, EventArgs e)
        {
            HttpContext context = ((HttpApplication)sender).Context;

            DtCms.Model.WebSet SiteConfig    = new DtCms.BLL.WebSet().loadConfig(Utils.GetXmlMapPath("Configpath"));
            string             killSqlFilter = SiteConfig.WebKillKeywords; //获取需要过滤的危险字符集
            //排除不需要过滤的目录
            bool   isKill      = true;
            string notKillPath = SiteConfig.WebManagePath + "|KindEditor"; //排除的目录列表

            string[] arrNotKillPath = notKillPath.Split('|');
            //取得发出请求的页面
            if (context.Request.UrlReferrer != null)
            {
                foreach (string str in arrNotKillPath)
                {
                    if (context.Request.UrlReferrer.ToString().ToLower().IndexOf(SiteConfig.WebPath + str.ToLower() + "/") > 0)
                    {
                        isKill = false;
                    }
                }
            }

            //遍历参数,管理目录和隐藏域除外
            if (isKill)
            {
                //遍历Post参数
                foreach (string i in context.Request.Form)
                {
                    if (i == "__VIEWSTATE")
                    {
                        continue;
                    }
                    if (DtCms.Common.Utils.SqlFilter(killSqlFilter, context.Request.Form[i].ToString()))
                    {
                        context.Response.Write("<script>window.alert('您提交的参数中含有非法字符!');history.back();" + " </" + "script>");
                        context.Response.End();
                    }
                }
                //遍历Get参数。
                foreach (string i in context.Request.QueryString)
                {
                    if (DtCms.Common.Utils.SqlFilter(killSqlFilter, context.Request.QueryString[i].ToString()))
                    {
                        context.Response.Write("<script>window.alert('您提交的参数中含有非法字符!');history.back();" + " </" + "script>");
                        context.Response.End();
                    }
                }
            }
        }
コード例 #3
0
        public void ProcessRequest(HttpContext context)
        {
            string action = context.Request.Params["action"];

            if (action == "add")
            {
                //取得站点配置信息
                DtCms.Model.WebSet webset = new DtCms.BLL.WebSet().loadConfig(Utils.GetXmlMapPath("Configpath"));

                int    _kindId;
                int    _parentId;
                string _code     = context.Request.Form["txtCode"];
                string _username = context.Request.Form["txtUserName"];
                int    _grade;
                string _content = context.Request.Form["txtContent"];

                //获得栏目ID
                if (!int.TryParse(context.Request.Params["kindId"] as string, out _kindId))
                {
                    context.Response.Write("{msg:0, msgbox:\"无法找到你所要评论的栏目!\"}");
                    return;
                }
                //获得信息ID
                if (!int.TryParse(context.Request.Params["parentId"] as string, out _parentId))
                {
                    context.Response.Write("{msg:0, msgbox:\"无法找到你所要评论的信息!\"}");
                    return;
                }
                //校检验证码
                if (string.IsNullOrEmpty(_code))
                {
                    context.Response.Write("{msg:0, msgbox:\"对不起,请输入验证码!\"}");
                    return;
                }
                if (context.Session["DtCode"] == null)
                {
                    context.Response.Write("{msg:0, msgbox:\"对不起,系统找不到生成的验证码!\"}");
                    return;
                }
                if (_code.ToLower() != (context.Session["DtCode"].ToString()).ToLower())
                {
                    context.Response.Write("{msg:0, msgbox:\"您输入的验证码与系统的不一致!\"}");
                    return;
                }

                //获得评价星级
                if (!int.TryParse(context.Request.Form["hidStar"] as string, out _grade))
                {
                    context.Response.Write("{msg:0, msgbox:\"请对此商品作出评价再提交!\"}");
                    return;
                }
                //检查用户名
                if (string.IsNullOrEmpty(_username))
                {
                    context.Response.Write("{msg:0, msgbox:\"对不起,请输入您的昵称!\"}");
                    return;
                }
                //检查输入的内容
                if (string.IsNullOrEmpty(_content))
                {
                    context.Response.Write("{msg:0, msgbox:\"请输入您要评论的信息内容!\"}");
                    return;
                }

                //开始写入数据
                DtCms.BLL.AllReviews   bll   = new DtCms.BLL.AllReviews();
                DtCms.Model.AllReviews model = new DtCms.Model.AllReviews();
                model.KindId   = _kindId;
                model.ParentId = _parentId;
                model.UserName = _username.Trim();
                model.Grade    = _grade;
                model.Content  = Utils.ToHtml(_content);
                model.IsLock   = webset.IsCheckComment; //评论是否需要审核
                model.AddTime  = DateTime.Now;
                bll.Add(model);
                context.Response.Write("{msg:1, msgbox:\"您的评论已提交成功,感谢您的支持!\"}");
                return;
            }
            else if (action == "list")
            {
                int kindId;
                int parentId;
                int pageIndex;
                int pageSize;

                //获得栏目ID
                if (!int.TryParse(context.Request.Params["kindId"] as string, out kindId))
                {
                    context.Response.Write("错误提示1,请勿提交非法字符!");
                    return;
                }
                //获得信息ID
                if (!int.TryParse(context.Request.Params["parentId"] as string, out parentId))
                {
                    context.Response.Write("错误提示2,请勿提交非法字符!");
                    return;
                }
                //获得当前页
                if (!int.TryParse(context.Request.Params["pageIndex"] as string, out pageIndex))
                {
                    context.Response.Write("错误提示3,请勿提交非法字符!");
                    return;
                }
                //获得每页大小
                if (!int.TryParse(context.Request.Params["pageSize"] as string, out pageSize))
                {
                    context.Response.Write("错误提示4,请勿提交非法字符!");
                    return;
                }

                DtCms.BLL.AllReviews bll = new DtCms.BLL.AllReviews();
                DataSet ds = bll.GetPageList(pageSize, pageIndex, "IsLock=0 and KindId=" + kindId + " and ParentId=" + parentId, "AddTime desc");
                //如果记录存在
                if (ds.Tables[0].Rows.Count > 0)
                {
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        DataRow dr = ds.Tables[0].Rows[i];
                        context.Response.Write("<div class=\"item\">\n");
                        context.Response.Write("<div class=\"user\">\n");
                        context.Response.Write("<span class=\"u-name\">网友:" + dr["UserName"].ToString() + "</span>\n");
                        context.Response.Write("<span class=\"star star" + dr["Grade"].ToString() + "\"></span>\n");
                        context.Response.Write("<span class=\"date-ask\">" + dr["AddTime"] + "</span>\n");
                        context.Response.Write("</div>\n");
                        context.Response.Write("<dl class=\"answer\">\n");
                        context.Response.Write("<dt><b></b>评论内容:</dt>\n");
                        context.Response.Write("<dd><div class=\"content\">" + dr["Content"].ToString() + "</div></dd>\n");
                        context.Response.Write("</dl>\n");
                        context.Response.Write("</div>\n");
                    }
                }
                else
                {
                    //context.Response.Write("<p>暂无评论信息!</p>");
                }
            }
        }
コード例 #4
0
        public void ProcessRequest(HttpContext context)
        {
            //取得处事类型
            string action = context.Request.Params["action"];

            //取得站点配置信息
            DtCms.Model.WebSet webset = new DtCms.BLL.WebSet().loadConfig(Utils.GetXmlMapPath("Configpath"));

            //===============================添加友情链接===============================
            if (action == "link")
            {
                string _code     = context.Request.Form["txtCode"];
                string _title    = context.Request.Form["txtTitle"];
                string _username = context.Request.Form["txtUserName"];
                string _usertel  = context.Request.Form["txtUserTel"];
                string _usermail = context.Request.Form["txtUserMail"];
                string _weburl   = context.Request.Form["txtWebUrl"];
                string _imgurl   = context.Request.Form["txtImgUrl"];
                int    _isimage;

                //校检验证码
                if (string.IsNullOrEmpty(_code))
                {
                    context.Response.Write("{msg:0, msgbox:\"对不起,请输入验证码!\"}");
                    return;
                }
                if (context.Session["DtCode"] == null)
                {
                    context.Response.Write("{msg:0, msgbox:\"对不起,系统找不到生成的验证码!\"}");
                    return;
                }
                if (_code.ToLower() != (context.Session["DtCode"].ToString()).ToLower())
                {
                    context.Response.Write("{msg:0, msgbox:\"您输入的验证码与系统的不一致!\"}");
                    return;
                }
                //检查网站标题
                if (string.IsNullOrEmpty(_title))
                {
                    context.Response.Write("{msg:0, msgbox:\"对不起,请输入您要链接的网站标题!\"}");
                    return;
                }
                //检查姓名
                if (string.IsNullOrEmpty(_username))
                {
                    context.Response.Write("{msg:0, msgbox:\"对不起,请输入您的姓名昵称!\"}");
                    return;
                }
                //检查联系电话
                if (string.IsNullOrEmpty(_usertel))
                {
                    context.Response.Write("{msg:0, msgbox:\"对不起,请输入您的联系电话!\"}");
                    return;
                }
                //检查网址
                if (string.IsNullOrEmpty(_weburl))
                {
                    context.Response.Write("{msg:0, msgbox:\"对不起,请输入您网站的网址!\"}");
                    return;
                }
                //检查链接类别
                if (!int.TryParse(context.Request.Form["rblIsImage"] as string, out _isimage))
                {
                    context.Response.Write("对不起,请选择要链接的类别!");
                    return;
                }
                //检查其它项
                if (string.IsNullOrEmpty(_usermail))
                {
                    _usermail = "";
                }
                if (string.IsNullOrEmpty(_imgurl))
                {
                    _imgurl = "";
                }
                //写入数据
                DtCms.Model.Links model = new DtCms.Model.Links();
                DtCms.BLL.Links   bll   = new DtCms.BLL.Links();
                model.Title    = _title.Trim();
                model.UserName = _username.Trim();
                model.UserTel  = _usertel.Trim();
                model.UserMail = _usermail.Trim();
                model.WebUrl   = _weburl.Trim();
                model.ImgUrl   = _imgurl.Trim();
                model.IsImage  = _isimage;
                model.IsLock   = 1;
                bll.Add(model);
                context.Response.Write("{msg:1, msgbox:\"您的链接请求已提交成功,请等待审核通过!\"}");
                return;
            }

            //===============================添加在线留言===============================
            if (action == "feedback")
            {
                string _code     = context.Request.Form["txtCode"];
                string _username = context.Request.Form["txtUserName"];
                string _usertel  = context.Request.Form["txtUserTel"];
                string _userqq   = context.Request.Form["txtUserQQ"];
                string _title    = context.Request.Form["txtTitle"];
                string _content  = context.Request.Form["txtContent"];

                //校检验证码
                if (string.IsNullOrEmpty(_code))
                {
                    context.Response.Write("{msg:0, msgbox:\"对不起,请输入验证码!\"}");
                    return;
                }
                if (context.Session["DtCode"] == null)
                {
                    context.Response.Write("{msg:0, msgbox:\"对不起,系统找不到生成的验证码!\"}");
                    return;
                }
                if (_code.ToLower() != (context.Session["DtCode"].ToString()).ToLower())
                {
                    context.Response.Write("{msg:0, msgbox:\"您输入的验证码与系统的不一致!\"}");
                    return;
                }
                //检查姓名
                if (string.IsNullOrEmpty(_username))
                {
                    context.Response.Write("{msg:0, msgbox:\"对不起,请输入您的昵称!\"}");
                    return;
                }
                //检查输入的标题
                if (string.IsNullOrEmpty(_title))
                {
                    context.Response.Write("{msg:0, msgbox:\"请输入您要留言的标题!\"}");
                    return;
                }
                //检查输入的内容
                if (string.IsNullOrEmpty(_content))
                {
                    context.Response.Write("{msg:0, msgbox:\"请输入您要留言的信息内容!\"}");
                    return;
                }
                //检查其它项
                if (string.IsNullOrEmpty(_usertel))
                {
                    _usertel = "";
                }
                if (string.IsNullOrEmpty(_userqq))
                {
                    _userqq = "";
                }
                //写入数据
                DtCms.Model.Feedback model = new DtCms.Model.Feedback();
                DtCms.BLL.Feedback   bll   = new DtCms.BLL.Feedback();
                model.UserName = _username.Trim();
                model.UserTel  = _usertel.Trim();
                model.UserQQ   = _userqq.Trim();
                model.Title    = _title.Trim();
                model.Content  = Utils.ToHtml(_content);
                model.IsLock   = webset.IsCheckFeedback; //留言是否需要审核
                model.AddTime  = DateTime.Now;
                bll.Add(model);
                context.Response.Write("{msg:1, msgbox:\"您的留言已提交成功,感谢您的支持!\"}");
                return;
            }
        }
コード例 #5
0
        public void ProcessRequest(HttpContext context)
        {
            //新增,取得站点配置信息
            DtCms.Model.WebSet webset = new DtCms.BLL.WebSet().loadConfig(Utils.GetXmlMapPath("Configpath"));
            //根目录路径,相对路径
            String rootPath = webset.WebPath + webset.WebFilePath + "/";
            //根目录URL,可以指定绝对路径,比如 http://www.yoursite.com/attached/
            String rootUrl = webset.WebPath + webset.WebFilePath + "/";
            //图片扩展名
            String fileTypes = "gif,jpg,jpeg,png,bmp";

            String currentPath = "";
            String currentUrl = "";
            String currentDirPath = "";
            String moveupDirPath = "";

            //根据path参数,设置各路径和URL
            String path = context.Request.QueryString["path"];
            path = String.IsNullOrEmpty(path) ? "" : path;
            if (path == "")
            {
                currentPath = Utils.GetMapPath(rootPath);
                currentUrl = rootUrl;
                currentDirPath = "";
                moveupDirPath = "";
            }
            else
            {
                currentPath = Utils.GetMapPath(rootPath) + path;
                currentUrl = rootUrl + path;
                currentDirPath = path;
                moveupDirPath = Regex.Replace(currentDirPath, @"(.*?)[^\/]+\/$", "$1");
            }

            //排序形式,name or size or type
            String order = context.Request.QueryString["order"];
            order = String.IsNullOrEmpty(order) ? "" : order.ToLower();

            //不允许使用..移动到上一级目录
            if (Regex.IsMatch(path, @"\.\."))
            {
                context.Response.Write("Access is not allowed.");
                context.Response.End();
            }
            //最后一个字符不是/
            if (path != "" && !path.EndsWith("/"))
            {
                context.Response.Write("Parameter is not valid.");
                context.Response.End();
            }
            //目录不存在或不是目录
            if (!Directory.Exists(currentPath))
            {
                context.Response.Write("Directory does not exist.");
                context.Response.End();
            }

            //遍历目录取得文件信息
            string[] dirList = Directory.GetDirectories(currentPath);
            string[] fileList = Directory.GetFiles(currentPath);

            switch (order)
            {
                case "size":
                    Array.Sort(dirList, new NameSorter());
                    Array.Sort(fileList, new SizeSorter());
                    break;
                case "type":
                    Array.Sort(dirList, new NameSorter());
                    Array.Sort(fileList, new TypeSorter());
                    break;
                case "name":
                default:
                    Array.Sort(dirList, new NameSorter());
                    Array.Sort(fileList, new NameSorter());
                    break;
            }

            Hashtable result = new Hashtable();
            result["moveup_dir_path"] = moveupDirPath;
            result["current_dir_path"] = currentDirPath;
            result["current_url"] = currentUrl;
            result["total_count"] = dirList.Length + fileList.Length;
            List<Hashtable> dirFileList = new List<Hashtable>();
            result["file_list"] = dirFileList;
            for (int i = 0; i < dirList.Length; i++)
            {
                DirectoryInfo dir = new DirectoryInfo(dirList[i]);
                Hashtable hash = new Hashtable();
                hash["is_dir"] = true;
                hash["has_file"] = (dir.GetFileSystemInfos().Length > 0);
                hash["filesize"] = 0;
                hash["is_photo"] = false;
                hash["filetype"] = "";
                hash["filename"] = dir.Name;
                hash["datetime"] = dir.LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss");
                dirFileList.Add(hash);
            }
            for (int i = 0; i < fileList.Length; i++)
            {
                FileInfo file = new FileInfo(fileList[i]);
                Hashtable hash = new Hashtable();
                hash["is_dir"] = false;
                hash["has_file"] = false;
                hash["filesize"] = file.Length;
                hash["is_photo"] = (Array.IndexOf(fileTypes.Split(','), file.Extension.Substring(1).ToLower()) >= 0);
                hash["filetype"] = file.Extension.Substring(1);
                hash["filename"] = file.Name;
                hash["datetime"] = file.LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss");
                dirFileList.Add(hash);
            }
            context.Response.AddHeader("Content-Type", "application/json; charset=UTF-8");
            context.Response.Write(JsonMapper.ToJson(result));
            context.Response.End();
        }
コード例 #6
0
        public void ProcessRequest(HttpContext context)
        {
            int aid;

            //获得首页图片位的ID
            if (!int.TryParse(context.Request.Params["id"] as string, out aid))
            {
                context.Response.Write("document.write('错误提示,请勿提交非法字符!');");
                return;
            }

            //检查首页图片位是否存在
            DtCms.BLL.Advertising abll = new DtCms.BLL.Advertising();
            if (!abll.Exists(aid))
            {
                context.Response.Write("document.write('错误提示,该首页图片位不存在!');");
                return;
            }

            //取得该首页图片位详细信息
            DtCms.Model.Advertising aModel = abll.GetModel(aid);

            //输出该首页图片位下的首页图片条,不显示未开始、过期、暂停首页图片
            DtCms.BLL.Adbanner bbll = new DtCms.BLL.Adbanner();
            DataSet            ds   = bbll.GetList("IsLock=0 and datediff(d,StartTime,getdate())>=0 and datediff(d,EndTime,getdate())<=0 and Aid=" + aid);

            if (ds.Tables[0].Rows.Count < 1)
            {
                context.Response.Write("document.write('该首页图片位下暂无首页图片内容');");
                return;
            }

            //=================判断首页图片位类别,输出首页图片条======================

            //新增,取得站点配置信息
            DtCms.Model.WebSet webset = new DtCms.BLL.WebSet().loadConfig(Utils.GetXmlMapPath("Configpath"));

            switch (aModel.AdType)
            {
            case 1:     //文字
                context.Response.Write("document.write('<ul>');\n");
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    //如果超出限制首页图片数量,则退出循环
                    if (i >= aModel.AdNum)
                    {
                        break;
                    }
                    DataRow dr = ds.Tables[0].Rows[i];
                    context.Response.Write("document.write('<li>');");
                    context.Response.Write("document.write('<a title=\"" + dr["Title"] + "\" target=\"" + aModel.AdTarget + "\" href=\"" + dr["LinkUrl"] + "\">" + dr["Title"] + "</a>');");
                    context.Response.Write("document.write('</li>');\n");
                }
                context.Response.Write("document.write('</ul>');\n");
                break;

            case 2:     //图片
                if (ds.Tables[0].Rows.Count == 1)
                {
                    DataRow dr = ds.Tables[0].Rows[0];
                    context.Response.Write("document.write('<a title=\"" + dr["Title"] + "\" target=\"" + aModel.AdTarget + "\" href=\"" + dr["LinkUrl"] + "\">');");
                    context.Response.Write("document.write('<img src=\"" + dr["AdUrl"] + "\" width=" + aModel.AdWidth + " height=" + aModel.AdHeight + " border=0 />');");
                    context.Response.Write("document.write('</a>');");
                }
                else
                {
                    context.Response.Write("document.write('<ul>');\n");
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        //如果超出限制首页图片数量,则退出循环
                        if (i >= aModel.AdNum)
                        {
                            break;
                        }
                        DataRow dr = ds.Tables[0].Rows[i];
                        context.Response.Write("document.write('<li>');");
                        context.Response.Write("document.write('<a title=\"" + dr["Title"] + "\" target=\"" + aModel.AdTarget + "\" href=\"" + dr["LinkUrl"] + "\">');");
                        context.Response.Write("document.write('<img src=\"" + dr["AdUrl"] + "\" width=" + aModel.AdWidth + " height=" + aModel.AdHeight + " border=0 />');");
                        context.Response.Write("document.write('</a>');\n");
                        context.Response.Write("document.write('</li>');\n");
                    }
                    context.Response.Write("document.write('</ul>');\n");
                }
                break;

            case 3:     //幻灯片
                StringBuilder picTitle = new StringBuilder();
                StringBuilder picUrl   = new StringBuilder();
                StringBuilder picLink  = new StringBuilder();
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    //如果超出限制首页图片数量,则退出循环
                    if (i >= aModel.AdNum)
                    {
                        break;
                    }
                    DataRow dr = ds.Tables[0].Rows[i];
                    picUrl.Append(dr["AdUrl"].ToString());
                    picLink.Append(dr["LinkUrl"].ToString());
                    if (i < ds.Tables[0].Rows.Count - 1)
                    {
                        picUrl.Append("|");
                        picLink.Append("|");
                    }
                }
                context.Response.Write("document.write('<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" d=scriptmain name=scriptmain codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0\" width=\"" + aModel.AdWidth + "\" height=\"" + aModel.AdHeight + "\">');\n");
                context.Response.Write("document.write('<param name=\"movie\" value=\"" + webset.WebPath + "images/focus.swf?width=" + aModel.AdWidth + "&height=" + aModel.AdHeight + "&bigSrc=" + picUrl + "&href=" + picLink + "\">');\n");
                context.Response.Write("document.write('<param name=\"quality\" value=\"high\">');\n");
                context.Response.Write("document.write('<param name=\"loop\" value=\"false\">');\n");
                context.Response.Write("document.write('<param name=\"menu\" value=\"false\">');\n");
                context.Response.Write("document.write('<param name=\"wmode\" value=\"transparent\">');\n");
                context.Response.Write("document.write('<embed src=\"" + webset.WebPath + "images/focus.swf?width=" + aModel.AdWidth + "&height=" + aModel.AdHeight + "&bigSrc=" + picUrl + "&href=" + picLink + "\" width=\"" + aModel.AdWidth + "\" height=\"" + aModel.AdHeight + "\" loop=\"false\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" type=\"application/x-shockwave-flash\" wmode=\"transparent\" menu=\"false\"></embed>');\n");
                context.Response.Write("document.write('</object>');\n");
                break;

            case 4:     //动画
                if (ds.Tables[0].Rows.Count == 1)
                {
                    DataRow dr = ds.Tables[0].Rows[0];
                    context.Response.Write("document.write('<object classid=\"clsid:D27CDB6E-AE6D-11CF-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0\" width=\"" + aModel.AdWidth + "\" height=\"" + aModel.AdHeight + "\">');\n");
                    context.Response.Write("document.write('<param name=\"movie\" value=\"" + dr["AdUrl"] + "\">');\n");
                    context.Response.Write("document.write('<param name=\"quality\" value=\"high\">');\n");
                    context.Response.Write("document.write('<param name=\"wmode\" value=\"transparent\">');\n");
                    context.Response.Write("document.write('<param name=\"menu\" value=\"false\">');\n");
                    context.Response.Write("document.write('<embed src=\"" + dr["AdUrl"] + "\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\"" + aModel.AdWidth + "\" height=\"" + aModel.AdHeight + "\" quality=\"High\" wmode=\"transparent\">');\n");
                    context.Response.Write("document.write('</embed>');\n");
                    context.Response.Write("document.write('</object>');\n");
                }
                else
                {
                    context.Response.Write("document.write('<ul>');\n");
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        //如果超出限制首页图片数量,则退出循环
                        if (i >= aModel.AdNum)
                        {
                            break;
                        }
                        DataRow dr = ds.Tables[0].Rows[i];
                        context.Response.Write("document.write('<li>');");
                        context.Response.Write("document.write('<object classid=\"clsid:D27CDB6E-AE6D-11CF-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0\" width=\"" + aModel.AdWidth + "\" height=\"" + aModel.AdHeight + "\">');\n");
                        context.Response.Write("document.write('<param name=\"movie\" value=\"" + dr["AdUrl"] + "\">');\n");
                        context.Response.Write("document.write('<param name=\"quality\" value=\"high\">');\n");
                        context.Response.Write("document.write('<param name=\"wmode\" value=\"transparent\">');\n");
                        context.Response.Write("document.write('<param name=\"menu\" value=\"false\">');\n");
                        context.Response.Write("document.write('<embed src=\"" + dr["AdUrl"] + "\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\"" + aModel.AdWidth + "\" height=\"" + aModel.AdHeight + "\" quality=\"High\" wmode=\"transparent\">');\n");
                        context.Response.Write("document.write('</embed>');\n");
                        context.Response.Write("document.write('</object>');\n");
                        context.Response.Write("document.write('</li>');\n");
                    }
                    context.Response.Write("document.write('</ul>');\n");
                }
                break;

            case 5:    //视频
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    //如果超出限制首页图片数量,则退出循环
                    if (i >= 1)
                    {
                        break;
                    }
                    DataRow dr = ds.Tables[0].Rows[i];
                    context.Response.Write("document.write('<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0\" width=" + aModel.AdWidth + " height=" + aModel.AdHeight + " viewastext>');\n");
                    context.Response.Write("document.write('<param name=\"movie\" value=\"" + webset.WebPath + "images/Player.swf\" />');\n");
                    context.Response.Write("document.write('<param name=\"quality\" value=\"high\" />');\n");
                    context.Response.Write("document.write('<param name=\"allowFullScreen\" value=\"true\" />');\n");
                    context.Response.Write("document.write('<param name=\"FlashVars\" value=\"vcastr_file=" + dr["AdUrl"].ToString() + "&LogoText=www.auto.cn&BarTransparent=30&BarColor=0xffffff&IsAutoPlay=1&IsContinue=1\" />');\n");
                    context.Response.Write("document.write('</object>');\n");
                }
                break;

            case 6:    //代码
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    //如果超出限制首页图片数量,则退出循环
                    if (i >= 1)
                    {
                        break;
                    }
                    DataRow       dr = ds.Tables[0].Rows[i];
                    StringBuilder sb = new StringBuilder(dr["AdRemark"].ToString());
                    sb.Replace("&lt;", "<");
                    sb.Replace("&gt;", ">");
                    sb.Replace("\"", "'");
                    context.Response.Write("document.write(\"" + sb.ToString() + "\")");
                }
                break;
            }
        }
コード例 #7
0
        public void ProcessRequest(HttpContext context)
        {
            //新增,取得站点配置信息
            DtCms.Model.WebSet webset = new DtCms.BLL.WebSet().loadConfig(Utils.GetXmlMapPath("Configpath"));
            //根目录路径,相对路径
            String rootPath = webset.WebPath + webset.WebFilePath + "/";
            //根目录URL,可以指定绝对路径,比如 http://www.yoursite.com/attached/
            String rootUrl = webset.WebPath + webset.WebFilePath + "/";
            //图片扩展名
            String fileTypes = "gif,jpg,jpeg,png,bmp";

            String currentPath = "";
            String currentUrl = "";
            String currentDirPath = "";
            String moveupDirPath = "";

            //根据path参数,设置各路径和URL
            String path = context.Request.QueryString["path"];
            path = String.IsNullOrEmpty(path) ? "" : path;
            if (path == "")
            {
                currentPath = Utils.GetMapPath(rootPath);
                currentUrl = rootUrl;
                currentDirPath = "";
                moveupDirPath = "";
            }
            else
            {
                currentPath = Utils.GetMapPath(rootPath) + path;
                currentUrl = rootUrl + path;
                currentDirPath = path;
                moveupDirPath = Regex.Replace(currentDirPath, @"(.*?)[^\/]+\/$", "$1");
            }

            //排序形式,name or size or type
            String order = context.Request.QueryString["order"];
            order = String.IsNullOrEmpty(order) ? "" : order.ToLower();

            //不允许使用..移动到上一级目录
            if (Regex.IsMatch(path, @"\.\."))
            {
                context.Response.Write("Access is not allowed.");
                context.Response.End();
            }
            //最后一个字符不是/
            if (path != "" && !path.EndsWith("/"))
            {
                context.Response.Write("Parameter is not valid.");
                context.Response.End();
            }
            //目录不存在或不是目录
            if (!Directory.Exists(currentPath))
            {
                context.Response.Write("Directory does not exist.");
                context.Response.End();
            }

            //遍历目录取得文件信息
            string[] dirList = Directory.GetDirectories(currentPath);
            string[] fileList = Directory.GetFiles(currentPath);

            switch (order)
            {
                case "size":
                    Array.Sort(dirList, new NameSorter());
                    Array.Sort(fileList, new SizeSorter());
                    break;
                case "type":
                    Array.Sort(dirList, new NameSorter());
                    Array.Sort(fileList, new TypeSorter());
                    break;
                case "name":
                default:
                    Array.Sort(dirList, new NameSorter());
                    Array.Sort(fileList, new NameSorter());
                    break;
            }

            Hashtable result = new Hashtable();
            result["moveup_dir_path"] = moveupDirPath;
            result["current_dir_path"] = currentDirPath;
            result["current_url"] = currentUrl;
            result["total_count"] = dirList.Length + fileList.Length;
            List<Hashtable> dirFileList = new List<Hashtable>();
            result["file_list"] = dirFileList;
            for (int i = 0; i < dirList.Length; i++)
            {
                DirectoryInfo dir = new DirectoryInfo(dirList[i]);
                Hashtable hash = new Hashtable();
                hash["is_dir"] = true;
                hash["has_file"] = (dir.GetFileSystemInfos().Length > 0);
                hash["filesize"] = 0;
                hash["is_photo"] = false;
                hash["filetype"] = "";
                hash["filename"] = dir.Name;
                hash["datetime"] = dir.LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss");
                dirFileList.Add(hash);
            }
            for (int i = 0; i < fileList.Length; i++)
            {
                FileInfo file = new FileInfo(fileList[i]);
                Hashtable hash = new Hashtable();
                hash["is_dir"] = false;
                hash["has_file"] = false;
                hash["filesize"] = file.Length;
                hash["is_photo"] = (Array.IndexOf(fileTypes.Split(','), file.Extension.Substring(1).ToLower()) >= 0);
                hash["filetype"] = file.Extension.Substring(1);
                hash["filename"] = file.Name;
                hash["datetime"] = file.LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss");
                dirFileList.Add(hash);
            }
            context.Response.AddHeader("Content-Type", "application/json; charset=UTF-8");
            context.Response.Write(JsonMapper.ToJson(result));
            context.Response.End();
        }