Always get exception for: response.Redirect(url)

M

moondaddy

I have some code I'm using from the OpenHack4 sample app from MS which
redirects a page to another page. Everytime I run the code I get an
exception, however the page still redirects to the correct page. I have
some other problems I'm trying to debug just after this code runs and I
don't know if they're somehow related to or effected by this exception, but
either way, I would like to get rid of the exception.

Here's the sub as is from MS (but I added the try/catch):

Friend Shared Sub RedirectWithMessage(ByVal url As String, ByVal message
As PageMessage)
Try
Dim cookie As New
System.Web.HttpCookie(Global.Session_PageMessage, message.ToString("d"))
Dim response As HttpResponse = HttpContext.Current.Response
response.Cookies.Add(cookie)
response.Redirect(url) 'Errors on this line
Catch ex As Exception
ErrLog(ex)
End Try
End Sub

ex is: {System.Threading.ThreadAbortException} System.Exception
and the StackTrace is:

at System.Threading.Thread.AbortInternal()
at System.Threading.Thread.Abort(Object stateInfo)
at System.Web.HttpResponse.End()
at System.Web.HttpResponse.Redirect(String url, Boolean endResponse)
at System.Web.HttpResponse.Redirect(String url)
at CharmPix.UrlHelper.RedirectWithMessage(String url, PageMessage message)
in c:\inetpub\wwwroot\CharmPix\Components\UrlHelper.vb:line 33" String

Is this supposed to happen? Can I avoid it? is there a better way?
 
K

Kevin Spencer

Try Response.Redirect(url, false)

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
M

moondaddy

Thanks that did it.

--
(e-mail address removed)
Kevin Spencer said:
Try Response.Redirect(url, false)

--
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
S

Steven Cheng[MSFT]

Hi Moondaddy,

Here are some further infos on the difference of Response.Redirect method's
two signatures style:
#HttpResponse.Redirect Method
http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemWebHttpRespons
eClassRedirectTopic.asp?frame=true

The below style Redirects a client to a new URL. Specifies the new URL and
whether execution of the current page should terminate.
[Visual Basic] Overloads Public Sub Redirect(String, Boolean)
[C#] public void Redirect(string, bool);

And here is a KB article which discussing the prolbem you encountered.
#PRB: ThreadAbortException Occurs If You Use Response.End,
Response.Redirect, or Server.Transfer
http://support.microsoft.com/?id=312629

I believe it also helpful to you. Thanks.



Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top