Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 使用aspx下载文件,在文件末尾添加符号_Asp.net_Download - Fatal编程技术网

Asp.net 使用aspx下载文件,在文件末尾添加符号

Asp.net 使用aspx下载文件,在文件末尾添加符号,asp.net,download,Asp.net,Download,我有一个aspx站点: <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Download.aspx.cs" Inherits="ATP.Management.Web.Download" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transit

我有一个aspx站点:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Download.aspx.cs" Inherits="ATP.Management.Web.Download" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    ...
    </div>
    </form>
</body>
</html>
请注意,我并不是真的在读c:\temp,这只是一些测试代码。这工作得很好,文件传输正常,但当我在记事本中打开文件时,它似乎附带了下载页面的
文本

为什么会发生这种情况?我该如何防止这种情况

在二进制写入后添加
Response.End()

 Response.ContentType = "application/octet-stream";
 Response.AddHeader("Content-disposition", "attachment; filename={0}".FormatWith(filename));
 var bytes = File.ReadAllBytes(@"c:\temp\" + filename);
 Response.BinaryWrite(bytes);