简体   繁体   中英

How make Response.Redirect inside a Asynchronous call method - c#

I have a try-catch inside a method that is called asynchronously. When an error occurs, inside the catch I have a Response.Redirect because I need to redirect to the login page.

This is my issue.

But my problem doesn't involve things that expire, so the idea of a timer isn't the best way to resolve it.

The method you are calling in your callback is outside of the context of a full page request. What you need to do is return in the response a value that prompts the browser to perform a redirect from the client side. This could be as simple as a javascript window.location call to login.aspx. The callback handler on the client side will need logic to recognise this and to eval the javascript (which will essentially execute it).

An alternative would be to return an error header to the browser and in the error handler set up in the ajax call, perform the window.location ='login.aspx'; call.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM