小小的下载功能,问题多多

 protected string LoadFiles()
        {
            StringBuilder strhtml = new StringBuilder();
            if (Session["studentmodel"] != null)
            {
                Maticsoft.Model.Student model = (Maticsoft.Model.Student)Session["studentmodel"];
                string filepath = CommonCode.GetDirPath(model.StudentType);
                Maticsoft.BLL.Submission bll = new Maticsoft.BLL.Submission();
                if (bll.Exists(model.StudentId))
                {
                    Maticsoft.Model.Submission submodel = bll.GetModel(model.StudentId);
                    string isexists = Server.MapPath("~/" + filepath + submodel.SubNewTitle);
                    if (!File.Exists(isexists)) {
                        return strhtml.Append("上传的文件已经移除").ToString();
                    }
                    strhtml.Append("<span>");
                    strhtml.Append("文档下载:");
                    strhtml.Append("<a href='" + filepath + Server.UrlEncode(submodel.SubNewTitle) + "'>");
                    strhtml.Append("" + submodel.SubTitle + "");
                    strhtml.Append("</a>");
                    strhtml.Append("</span>");
                    return strhtml.ToString();
                }
                else
                {
                    return strhtml.Append("暂无上传").ToString();
                }

            }
            else
                return strhtml.Append("暂无上传").ToString();
        }

由于文件路径中有中文存在。Server.UrlEncode是一定要注意的,否则会有404找不到路径的错误。

放到服务器上,下载文件时又出现了新的错误。HTTP 错误 404.11 - Not Found 请求筛选模块被配置为拒绝包含双重转义序列的请求,

解决方案在这里

1.单击 开始 。 在 开始搜索 框中, 键入 Notepad. 右击 记事本 , 然后单击 作为管理员运行 。

注意 如果提示用于管理员密码或用于确认, 键入密码, 或单击 继续 。

2.在 文件 菜单上, 单击 打开 。 在 文件名 框中, 键入 %windir%\system32\inetsrv\config\applicationhost.config然后单击 打开 。
  
3.在 ApplicationHost.config 文件, 定位 文件中的 configuration/system.webServer/security/requestFiltering/下 
<requestFiltering> 节点。大约360行

将<requestFiltering>

改为

<requestFiltering allowDoubleEscaping="true">

即可

posted @ 2013-10-12 11:43  程序新青年  阅读(175)  评论(0编辑  收藏  举报
============================================================================== 青春匆匆,很多人都有自己的座右铭,鞭策自己前进,当没看到座右铭的时候又忘了自己要干什么,就这样天天立志,志天天立,最终还是那个初出茅庐的小菜鸟。从现在开始,慢慢去改掉懒惰的习惯。慢慢去加强学习,直到慢慢成功。==============================================================================