Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Response Redirect cannot be called in Page callback?

I am getting the following error when I leave my web inactive for a while

"Response.Redirect.cannot be called in a Page callback."

I'm storing the user ids in session and during page load I check to see if the user id exists if not then I redirect them to the login page.

I am using devexpress controls, How can I get the redirect to work?

like image 567
Robert Avatar asked Jul 16 '10 23:07

Robert


4 Answers

if (Page.IsCallback) ASPxWebControl.RedirectOnCallback("~/Login.aspx");

http://documentation.devexpress.com/#AspNet/DevExpressWebASPxClassesASPxWebControl_RedirectOnCallbacktopic

like image 92
AYCAN Avatar answered Nov 10 '22 08:11

AYCAN


Try using the Response.RedirectLocation property instead which works during callback.

HttpResponse.RedirectLocation Property on MSDN

like image 7
Fredrik Eder Avatar answered Nov 10 '22 08:11

Fredrik Eder


You can usually turn callbacks off for devexpress controls like the ASPxGridView using the "EnableCallbacks" property. This will obviously cause the controls to use postbacks, but it will also allow Response.Redirect to do its job.

like image 2
AGoodDisplayName Avatar answered Nov 10 '22 10:11

AGoodDisplayName


HttpResponse.RedirectLocation Property on MSDN works for me in same problem

here is the sample code from Msdn

Response.StatusCode = 301;
Response.Status = "301 Moved Permanently";
Response.RedirectLocation = "http://www.newurl.com ";
Response.End();
like image 2
Muhammad Raheel Avatar answered Nov 10 '22 08:11

Muhammad Raheel