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 3393172
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:01:09+00:00 2026-05-18T04:01:09+00:00

Some scenarios to ponder. There is a legacy code which has following implementation Example1

  • 0

Some scenarios to ponder. There is a legacy code which has following implementation Example1 and Example2. If we try to implement MSDN recommendation then the legacy code fails.

Here is a Legacy code example:

Example 1:

void Page_Load() {
  .... some code
  if(condition) {
     /// some condition
  } else {
     RedirectPage(url);
  }

  // another code block
  // some other conditions. 
}
 

Example 2:

a. File1.ascx
void Page_Load() {
  try {
    .. some code
    base.CheckPreference();
    RedirectPage(defaultPage);
  }
  catch(Exception ex) {
    ExceptionHandling.GetErrorMessage(ex);
  }
}
b. BaseClass.cs  // this is the base class 
void CheckPreference() {
  try {
     if(condition) {
        RedirectPage(url1);
     } else if(condition2) {
        RedirectPage(url2);
     } else {
        // update session
     }

  }
  catch(Exception ex) {
     ExceptionHandling.GetErrorMessage(ex);
     throw;
  }
}

void RedirectPage(string url) {
  Response.Redirect(url);
}

One possible way is to add a boolean field in the class e.g endExecution, set the field to true whenever RedirectPage is called.

We have to update RedirectPage code see code snippet below:

// Updated code - MSDN recommendation.
void RedirectPage(url) {
  Response.Redirect(url, false);
  this.Context.ApplicationInstance.CompleteRequest();
  endExecution = true;
}

Please suggest some other better ways to improve the legacy code implementation.

  • 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-18T04:01:09+00:00Added an answer on May 18, 2026 at 4:01 am

    Probably the most unintuitive thing for folks issuing a redirect is that in our minds we’ve already returned from the method what we call Respond.Redirect (or whatever the equivilent is in your language/platform of the day. All we’ve done is call a method.

    Bottom line is that you have to stop processing the request to avoid trying to commit to responses for the same request. That would throw an exception on just about any platform I’ve worked with.

    ASP.NET MVC improved this with the ActionResponse so that you are returning from the method (and terminating the remainder of request processing) with code that looks like this:

    return Redirect(url);
    

    Bottom line is that you need to get in the habit of returning from your event right after you perform your redirect. Any deviation from that habit needs to be documented in the code why. This will help make the application perform the way you expect.

    The approach that you’ve taken is perfectly reasonable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As I understood from this post , there are some scenarios where foreign keys
In some scenarios I need a wide version of an entity with many properties
What are some scenarios where MultiView would be a good choice? The MultiView control
I am using Selenium IDE to record some scenarios and wanted to check if
In an app I'm profiling, I found that in some scenarios this function is
Is there some clever way of getting the date and time of when the
I am currently working on some simple custom allocators in c++ which generally works
I am working on building some pseudo-intelligent caching into a LINQ query provider .
Google Analytics use some query parameters to identify campaigns and to do cookie control.
I recently read in Fowler's PofEA that some database engines allow you to defer

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.