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) {
} else {
RedirectPage(url);
}
}
Example 2
a. File1.ascx
void Page_Load() {
try {
.. some code
base.CheckPreference();
RedirectPage(defaultPage);
}
catch(Exception ex) {
ExceptionHandling.GetErrorMessage(ex);
}
}
b. BaseClass.cs
void CheckPreference() {
try {
if(condition) {
RedirectPage(url1);
} else if(condition2) {
RedirectPage(url2);
} else {
}
}
catch(Exception ex) {
ExceptionHandling.GetErrorMessage(ex);
throw;
}
}
void RedirectPage(string url) {
Response.Redirect(url);
}
One possible way is to set a class boolean field e.g endExecution, set the field to true whenever RedirectPage is called. We have to update RedirectPage code see code snippet below:
void RedirectPage(url) {
Response.Redirect(url, false);
this.Context.ApplicationInstance.CompleteRequest();
}
Please suggest some other better ways to improve the legacy code implementation.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.