簡體   English   中英

為什么Response.End不起作用?

[英]why Response.End Not working?

可能是一個重復的問題。 但是我的情況有所不同。 我有一個頁面可以下載文本文件。 首先在頁面中,我將文本文件解密為string plainText 然后將該字符串寫入文件,然后上傳到名為“解密文件”的文件夾。 解密文件並刪除以前保存的文件的下載。

這是我的下載代碼

                //Write the decrypted text to folder in the server.
                System.IO.File.WriteAllText(Server.MapPath("~/Decrypted Files/" + FileName), plainText);

                //Code for Download
                Response.Clear();
                Response.ContentType = "application/octet-stream";
                Response.AddHeader("Content-Disposition", "attachment; filename='" + FileName + "'");
                Response.WriteFile(Server.MapPath("~/Decrypted Files/" + FileName));

                //Delete File from the folder
                if (System.IO.File.Exists(Server.MapPath("~/Decrypted Files/" + FileName)))
                {
                    System.IO.File.Delete((Server.MapPath("~/Decrypted Files/" + FileName)));
                }

                Response.End();

但是代碼執行不會從Response.End();繼續Response.End(); .aspx頁未完成其加載。 我的代碼有什么問題?

現在我得到了我的代碼有什么問題。 在結束之前,我刪除了文件。 所以我更改了代碼,如下所示,一切正常。

                //Write the decrypted text to folder in the server.
                System.IO.File.WriteAllText(Server.MapPath("~/Decrypted Files/" + FileName), plainText);

                //Code for Download
                Response.Clear();
                Response.ContentType = "application/octet-stream";
                Response.AddHeader("Content-Disposition", "attachment; filename='" + FileName + "'");
                Response.WriteFile(Server.MapPath("~/Decrypted Files/" + FileName));
                Response.Flush();

                //Delete File from the folder
                if (System.IO.File.Exists(Server.MapPath("~/Decrypted Files/" + FileName)))
                {
                    System.IO.File.Delete((Server.MapPath("~/Decrypted Files/" + FileName)));
                }
                HttpContext.Current.Response.End();

將該按鈕(您要用於導出的按鈕)放在更新面板中

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM