为了下载我写了下面的代码服务器无法HTTP标头后清晰头已被送往
[AcceptVerbs(HttpVerbs.Post | HttpVerbs.Get)] public ActionResult Download(string fileName) {
try {
string filepath = @"C:\shadow_copy.rar";
Response.ClearHeaders();
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename= " + fileName.TrimEnd());
Response.AddHeader("Content-Length", fileName.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.WriteFile(filepath.TrimEnd());
Response.End();
}
catch (Exception exp)
{
//
}
return Redirect("http://mysite.com");
}
我也用
一个文件,如果(!Response.IsRequestBeingRedirected)//将不叫的Response.Redirect(“http://www.google.com”)
但它显示错误
“后,HTTP标头已被送往不能重定向。”
你想完成什么?下载文件或重定向用户。你必须选择一个到另一个。 – 2011-12-22 09:40:42