您的位置:首页 > 其它

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

2013-10-12 11:43 309 查看
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">

即可
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐