zoukankan      html  css  js  c++  java
  • 小小的下载功能,问题多多

     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%system32inetsrvconfigapplicationhost.config然后单击 打开 。
      
    3.在 ApplicationHost.config 文件, 定位 文件中的 configuration/system.webServer/security/requestFiltering/下 
    <requestFiltering> 节点。大约360行

    将<requestFiltering>

    改为

    <requestFiltering allowDoubleEscaping="true">

    即可

  • 相关阅读:
    关于this的指向问题
    blued面经
    数美(sm)面经
    xue球 面经
    jquery中的$("#id")与document.getElementById("id")的区别
    如何知道iframe文件下载download完成
    前端linux基础
    Vue.js 初级面试题
    React 面试题
    从输入URL到页面加载的过程
  • 原文地址:https://www.cnblogs.com/zlzly/p/3364958.html
Copyright © 2011-2022 走看看