ASP应用程序中Debug和Release版本之间的差异输出

时间:2017-08-21 04:03:58

标签: c# asp.net debugging filestream

我在我的应用程序中编写了以下代码

fs = new FileStream(OutputFilePath, FileMode.CreateNew, FileAccess.ReadWrite, FileShare.Read);
StringBuilder sb = new StringBuilder();
using (StreamWriter writer = new StreamWriter(fs, Encoding.UTF8, 512))
{
  //add some text to sb
  writer.Write(sb.ToString());
  writer.Close();
}
finally
{
  if (fs != null)
  {
     fs.Close();
     fs.Dispose();
  }

现在,当我使用应用程序并单击输出按钮时,我的输出文件具有在所需输出后使用页面的html代码。但是当我使用调试工具查找我的代码有什么问题时,每件事情都是完美的!甚至我的输出文件!

编辑:这是我的输出

调试版本(右输出)

 //Exact text that I added to sb above 

发布版本(输出错误)

//Exact text that I added to sb above 
<!DOCTYPE html ....//All html Code of using page that I download output file from it

请原谅我的语法错误,英语不是我的母语。

1 个答案:

答案 0 :(得分:0)

我怀疑你想要这些内容:

StringBuilder sb = new StringBuilder();
sb.Add("Some text");

// Clear anything the page has begun to buffer. We don't want that.
Response.ClearHeaders();
Response.ClearContent();


// Write something to the Response.OutputStream here
Response.ContentType = "text/plain";
Response.CharSet = "utf-8";
Response.OutputStream.Write(System.Text.Encoding.UTF8.GetBytes(sb.ToString()));

// Send to the client immediately.
Response.Flush();
// Prevent any more being added by ASP.Net
Response.SuppressContent = true;