Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3676108
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T03:03:35+00:00 2026-05-19T03:03:35+00:00

When I want to redirect a user who has lost session state back to

  • 0

When I want to redirect a user who has lost session state back to the StartPage I find Response.Redirect(“~/StartPage.aspx”) causes the error “Response Redirect Cannot Be Called In A Page Callback”. Therefore in a Page.IsCallback situation I want to add javascript to do the redirect – this works – see code below.

protected void ForceBackToStartPage()
{
    if (Page.IsCallback)
    {
        string fullLoginUrl = ConvertRelativeUrlToAbsoluteUrl( "~/StartPage.aspx" );
        string script = string.Format("window.location.href = '{0}';", fullLoginUrl);
        ClientScriptManager cm = Page.ClientScript;
        cm.RegisterClientScriptBlock(GetType(), "redirect", script, true);
        //Response.Flush();
        //Response.End();
    }
    else
    {
        Response.Redirect("~/StartPage.aspx");
    }

}

After I have added the javascript in this section the code continues to process normally leaving this function and going off to other processing sections of the webpage – probematic as the user has no session data. Ideally I’d want processing of this web page to finish – and for the page to return in a valid state so that the user gets redirected.

Is this possible?

I thought Response.Flush(); Response.End(); might do the trick – but the webpage sent back to the browser causes XML Parse errors.

Further info: I check for missing session data in a few places (depending on the webpage – this code is in lots of web pages) – for instance – PageLoad and from some submit button methods.

Before the new method I used this code e.g.:

protected void Page_Load(object sender, EventArgs e)
{
    if ((string)Session["OK"] != "OK")
    {
        // the session has timed out - take them back to the start page
        Response.Redirect("~/StartPage.aspx");
    }

...rest of processing

Now it’s invoked like this:

protected void Page_Load(object sender, EventArgs e)
{
    if ((string)Session["OK"] != "OK")
    {
        // the session has timed out - take them back to the start page
        ForceBackToStartPage();
    }

...rest of processing

so I could obviously use

else
{
…rest of processing
}

but I was hoping not to have to do that as SVN Source Control takes that to mean I’ve re-written the whole ‘rest of processing’ section. This is problematic as when I merge from a branch into the trunk it does not check I am not overwriting mods because it assumes it’s all new code coming in.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T03:03:36+00:00Added an answer on May 19, 2026 at 3:03 am

    I was thinking about this again recently and realised the very obvious answer. Forget nicely structured code, as being part of an error trap this is a special case, and use a return; after the ‘ForceBackToStartPage’ method invocation:

    protected void Page_Load(object sender, EventArgs e)
    {    
     if ((string)Session["OK"] != "OK")  
       {        
           // the session has timed out - take them back to the start page    
           ForceBackToStartPage();  
           return; 
       }  
    
    ...rest of processing
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a method that where I want to redirect the user back to
I want to redirect a user who gets from page.php?letter=A&num=2 to the following address:
I use Ruby On Rails and devise gem. I want redirect user after registration,
I just want to redirect the user to google search when he type some
I want to redirect from an action in one controller to an action in
I am using ASP.NET 2.0 C#. I want to redirect all request for my
I want to add the link tags to redirect my web-site to my OpenID
I want: all links which not contained filename (not .html, .jpg, .png, .css) redirect
Whenever a user visits Page A on my site, I immediately redirect him to
I don't want to deal with users who have javascript turned off, so I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.