爲了下載我寫了下面的代碼服務器無法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