c# - ThreadAbortException in server transfer in asp.net -
i getting error unable evaluate look because code optimized or native frame on top of phone call stack.
while executing line
server.transfer("payment.aspx?vpc_channelid=2", true);
so pointed out reply http://stackoverflow.com/a/1252119/1169180 & http://stackoverflow.com/a/11130517/1169180
i changed code
protected void page_load(object sender, eventargs e) { seek { usercontext conobj = new usercontext(); httpcontext currcontext = httpcontext.current; if (!ispostback) { // code } else { string usercontext = hdncontextobj.value; conobj = jsonconvert.deserializeobject<usercontext>(usercontext); currcontext.items.add("context", conobj); seek { server.transfer("payment.aspx?vpc_channelid=2", true); } grab (threadabortexception xobj) { } { server.transfer("payment.aspx?vpc_channelid=2", true); } } } grab (exception xobj) { response.write("exception : " + xobj.message); } }
still getting same exception in out grab block
also pointed out here http://support.microsoft.com/kb/312629/en-us/ used server.execute
didnt redirect payment.aspx
page instead refreshes.
the exception raised because thread running operation forced terminate in multiple locations due transfer. such, safe ignore exception linked answers suggest.
you can ignore exception catching exception , not throwing it.
try { server.transfer("payment.aspx?vpc_channelid=2", true); } catch(threadabortexception) { // exception ignored: thread abort = discontinue processing on current page }
alternatively, msdn article suggest, can utilize server.execute
instead.
to work around problem, utilize 1 of next methods:
for response.end
, phone call httpcontext.current.applicationinstance.completerequest
method instead of response.end
bypass code execution application_endrequest
event.
for response.redirect
, utilize overload, response.redirect(string url, bool endresponse)
passes false
endresponse
parameter suppress internal phone call response.end
. example:
response.redirect ("nextpage.aspx", false);
if utilize workaround, code follows response.redirect executed.
for server.transfer
, utilize server.execute
method instead.
// clarification on server.execute
the msdn doc clarifies usage of server.execute
. of import remember not redirect, acts function call. code after phone call executed. if not want code execute can utilize return
, or response.end
.
in op's example, code might when using server.execute
protected void page_load(object sender, eventargs e) { seek { usercontext conobj = new usercontext(); httpcontext currcontext = httpcontext.current; if (!ispostback) { // code } else { string usercontext = hdncontextobj.value; conobj = jsonconvert.deserializeobject<usercontext>(usercontext); currcontext.items.add("context", conobj); server.execute("payment.aspx?vpc_channelid=2", true); response.end(); // or return; } } grab (exception xobj) { response.write("exception : " + xobj.message); } }
c# asp.net
No comments:
Post a Comment