5

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?

2
  • 1
    possible duplicate stackoverflow.com/questions/1538749/…
    – µBio
    Jul 16, 2010 at 23:52
  • @Lucas - I don't think so. That questioner just wanted to stop the error and was happy with using if (!Page.IsCallback) I think @Kyle wants some way to redirect the user to the login page if their session has expired. Jul 17, 2010 at 0:09

7 Answers 7

7

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

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

0
7

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

HttpResponse.RedirectLocation Property on MSDN

2

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.

2

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();
1

You can't get the redirect to work in a callback. Perhaps instead of doing Response.Redirect on the server you could write some value in a <script type="text/javascript"/> block and set the window.location.href (redirect) on the client side?

1

You can use:

string TARGET_URL = ...;
if(Page.IsCallback)
    DevExpress.Web.ASPxClasses.ASPxWebControl.RedirectOnCallback(TARGET_URL);
else
    Response.Redirect(TARGET_URL);

Refer at KA18851 in Devexpress

0

Indeed, it is impossible to use the Response.Redirect during a callback. Please refer to the following blog post in this regard.

http://community.devexpress.com/blogs/aspnet/archive/2008/08/25/how-to-redirect-to-login-page-after-session-timeout.aspx

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.