c# - Response.Redirect not working inside Async callback -
c# - Response.Redirect not working inside Async callback -
sorry in advance if duplicate have tried many threads nil seem give solution worked me. hence why posting it.
i using async httpwebrequest.begingetresponse , in callback function calling response.redirect throws next exception response not available in context
i have tried utilize javascript redirection didn't work well. below code.
private void get_personaldetails() { httpwebrequest myhttpwebrequest = (httpwebrequest)webrequest.create(url); requeststate myrequeststate = new requeststate(); myrequeststate.request = myhttpwebrequest; myrequeststate.setheaders(); iasyncresult result = (iasyncresult)myhttpwebrequest.begingetresponse( new asynccallback(respcallback), myrequeststate); } private void respcallback(iasyncresult asynchronousresult) { seek { // state of request asynchronous. requeststate myrequeststate = (requeststate)asynchronousresult.asyncstate; httpwebrequest myhttpwebrequest = myrequeststate.request; myrequeststate.response = (httpwebresponse)myhttpwebrequest.endgetresponse(asynchronousresult); // read response stream object. string res = utility.readresponse(myrequeststate.response); response.redirect("decision.aspx"); clientscript.registerstartupscript(gettype(), "hwa", "alert('do something');", true); page.clientscript.registerstartupscript(this.gettype(), "alert", "redirect();", true); return; } catch(webexception e){} } c# .net asynchronous httpwebrequest response.redirect
Comments
Post a Comment