473,903 Members | 3,258 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help with Response.Redire ct(URL,True) behavior

We are getting a behavior on a Response.Redire ct("SomeUrl", True) that I'm
hoping someone can explain. This all refers to the code snip at the end. By
the way, this is all VB ASP.NET v1.0 code.

So we have the Page_Load event of an ASPX page fire which in the snip you
see calls "SomeMethod ". Also you see in Page_Load two Catch statements. The
first is "SpecialExcepti on". We created our own extended exception (inherits
from ApplicationExce ption) class to handle certain properties and
functionality not in any standard .NET Exception. The second Catch in
Page_Load traps any other possible exceptions, creates a new
"SpecialExcepti on", sets certain properties based on the exception that was
raised and calls "DisplayMet hod" to perform needed functions.

Anyway, "SomeMethod " gets called and in there let's say a DivideByZero
exception happens for the sake of an example. In "SomeMethod ", the error is
trapped at "Catch ex As Exception". A new SpecialExceptio n is created,
populated and then passed to method "DisplayErr or".

In "DisplayErr or" you see we handle logging, some other error info massaging
and then finally attempt to do a redirect to our error display page.
Originally we had False in the Redirect method, but since execution would
continue, we'd have other methods finish getting called (some of which made
DB calls), etc. Not wanting to incur all that extra and unnecessary
method/DB calling, we decided to have the current page processing
stop...hence the True for the end response parm. Knowing that raises its own
error, we catch for the ThreadAbortExce ption and "eat" that error...or so we
thought.

It turns out that even though we explicitly trap for that
TreadAbortExcep tion error, it still bubbles up the stack. The DivideByZero
error popped in "SomeMethod " and was handled with "Catch ex As Exception"
which then did the "Call DisplayError(Ne w
SpecialExceptio n(ex.Message,ex .StackTrace,etc ))". In DisplayError we handled
the error, did the Redirect and trapped the ThreadAbortExce ption. From
DisplayError, execution continued back at the "Catch ex As Exception" handler
in "SomeMethod " and then I expected execution to exit from Page_Load
immediately and pick back up at our error display page based on the
Response.Redire ct. Well instead, execution picked back up in Page_Load at
its "Catch ex As Exception" error catch and then itself tries to "Call
DisplayError(Ne w SpecialExceptio n(ex.Message,ex .StackTrace,etc ))".
Furthermore, the "ex" error variable set up there says it is handling the
ThreadAbortExce ption that I thought we already handled in DisplayError.
Fortunately in DisplayError we do some Session checking and see we've already
handled/logged an error so we don't try to do it again and also do not try to
do another Response.Redire ct. Execution does finally make it to our error
display page, but I am trying to understand why the "Catch ex As Exception"
in Page_Load is catching the ThreadAbortExce ption that was thrown, and
supposedly already trapped, in DisplayError.

Here's the pseudo-snip:
===============
Public Sub Page_Load()
Try
...
Call SomeMethod
...
Catch sx As SpecialExceptio n
Call DisplayError(sx ) method to log and show user message
Catch ex As Exception
Call DisplayError(Ne w SpecialExceptio n(ex.Message,ex .StackTrace,etc ))
End Try
End Sub
Public Sub SomeMethod
Try
...
***Let's just say DivideByZero pops here***
Some Processing
More Processing
...
Catch sx As SpecialExceptio n
Call DisplayError(sx ) method to log and show user message
Catch ex As Exception
Call DisplayError(Ne w SpecialExceptio n(ex.Message,ex .StackTrace,etc ))
End Try
End Sub
Public Sub DisplayError(By Ref Exception As SpecialExceptio n)
Try
Handle Logging
Perform Other error-massaging
Try
Response.Redire ct("OurCustomEr rorDisplayPage. aspx", True)
Catch tae As System.Threadin g.ThreadAbortEx ception
Eat the Redirect's abort exception here
End Try
Catch ex As Exception
Eat any other possible exception here
End Try
End Sub
============

Thanks in advance.

-Mike
Nov 19 '05 #1
1 2751
Seems I just read the reason why this is happening in online docs for the
ThreadAbortExce ption. Per the docs:
=============== ===
When a call is made to the Abort method to destroy a thread, the common
language runtime throws a ThreadAbortExce ption. ThreadAbortExce ption is a
special exception that can be caught, but it will automatically be raised
again at the end of the catch block. When this exception is raised, the
runtime executes all the finally blocks before killing the thread. Since the
thread can do an unbounded computation in the finally blocks, you must call
the Join method to guarantee that the thread has died. Join is a blocking
call that does not return until the thread actually stops executing.
=============== ===

So it automatically gets raised again at the end of each catch block. Argh!
Any other suggestions for a "clean" way to handle this? Again we want to
avoid all that extra method/DB calling.

Thanks.

-Mike

"MikeM" wrote:
We are getting a behavior on a Response.Redire ct("SomeUrl", True) that I'm
hoping someone can explain. This all refers to the code snip at the end. By
the way, this is all VB ASP.NET v1.0 code.


Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
8242
by: timothy ma and constance lee | last post by:
Sirs How can i use javascript to redirect the url in the drop list box once the event onchnage is triggered?
1
3317
by: VMI | last post by:
I'm a ASP.Net beginner, so please don't laugh :-)) In the button of my initial aspx page, I have this code that sends a URL with parameters my other page: url="ZMResult.aspx?Address1= this.txt_add1.Text + "&Address2=" + this.txt_add2.Text; Response.Redirect(url);
2
1984
by: feng | last post by:
My users who try to access a page before login are redirected to my login page. Then after they successfully login, my login page will redirect the user to the page they intended to go through this line: FormsAuthentication.RedirectFromLoginPage(strUserName, False) What I want now is that I want to capture the origional url that the use intented to go BEFORE the user logs in. I
2
2877
by: Dr. Paul Caesar - CoullByte (UK) Limited | last post by:
Hi, I have created a Logout ASP.NET application using Forms Authentication. When a user logs out they get a confirmation page confirming logout and a button to click to return to the homepage. We have the page designed so that if the user is not authenticated then they get redirected using Response Redirect method to the homapage.
2
4178
by: porko | last post by:
I want to be able to programmatically log a user in as a guest and redirect them to a different page. Is there any way to do a RedirectFromLoginPage() and explicity specify the page to which the user will be redirected after the login? -- p
6
1331
by: ABC | last post by:
How to redirect URL to new window?
3
3129
by: guillermojco | last post by:
Hi, I've got an ASP.NET page that returns XLS, DOC, PDF and other files from binary fields in a database. The problem is that MS-Excel 2007 shows a security warning when trying to open the file because its name is page.ASPX instead of page.XLS (the file opens properly when this warning is accepted by the user). I thing the problem would solve if I can change the response URL from
2
4683
by: nil81 | last post by:
Hello Friends, I want to create a blog for the user that register to my site(for example www.test.com) after that I want to redirect user to www.user.test.com. That is just like in blogger.com. How can I perform this task is I did to create a subdomain for every user that register my site or just to create a page and redirect it www.user.test.com thorug .htacces. please if anybody can guide me to perform this task. ...
2
1998
by: =?Utf-8?B?UHJpeWE=?= | last post by:
Hi, I wanted to redirect all requests to my website to a maintenance page for a duration of 3 hours. It is any requests coming to www.abc.com or www.abc.com/index.aspx or www.abc.com/book/index.aspx........ or any requests for directories / subdomains / pages under www.abc.com to be redirected to outage.aspx. This outage.aspx is in teh local computer. How do i specify wildcards? How do i configure the settings in IIS6.0. Pls let me know....
0
9999
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10873
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10500
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9684
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8048
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7206
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5894
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4308
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.