2014-07-26 29 views
3

我們被告知,該網站有以下錯誤:HttpContext.Current.Response.Flush()與Response.Redirect的假

Exception Thread was being aborted., , at System.Threading.Thread.AbortInternal() 
at System.Threading.Thread.Abort(Object stateInfo) 
at System.Web.HttpResponse.End() 

Upoin調查我們發現,重定向的方法應該進行修改。

當前代碼:Response.Redirect(URL)

應通知如下:Response.Redirect(URL, false)

這並不能解決問題,也可以通過微軟建議:http://support.microsoft.com/kb/312629/en-us

然而,我們也遇到了下面的代碼:

response.Flush();     
HttpContext.Current.Response.Flush(); 
HttpContext.Current.Response.SuppressContent = true; 
HttpContext.Current.ApplicationInstance.CompleteRequest(); 

參考:http://dotnetplussqlserver.blogspot.in/2014/01/excel-download-responseend-throwing.html

有人可以幫助我們澄清哪種方法更好嗎?相互之間又有什麼意義呢? 我們只是想要簡單的重定向。

謝謝。

回答

-1

關於Response.Reditect如果你看一下該方法的MSDN Documentation Page簽名

public void Redirect(
    string url, 
    bool endResponse 
) 

哪裏endResponse

endResponse Type: System.Boolean

Indicates whether execution of the current page should terminate. 

所以,當你說Response.Reditect(URL, false)會重定向到直接提到URL不處理進一步的當前頁面。

下面從文檔頁面引用:

When you use this method in a page handler to terminate a request for one page and start a new request for another page, set endResponse to false and then call the CompleteRequest method. If you specify true for the endResponse parameter, this method calls the End method for the original request, which throws a ThreadAbortException exception when it completes. This exception has a detrimental effect on Web application performance, which is why passing false for the endResponse parameter is recommended.

+1

@Downvoter,護理髮表評論與投票向下沿? – Rahul

+0

謝謝你的細節,但正如你可以看到我不問爲什麼我們應該用戶重載重定向方法。我很想知道這是否是最好的方法?或者我應該使用response.Flush(); – TechTurtle

+0

@TechTurtle,更好的是非常流行和基於觀點,但我沒有看到很多人使用它,而是主要推薦使用'Response.Reditect'方法。 – Rahul