473,396 Members | 1,917 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Cancel a Response.Redirect

Tim
Hello,
Is there a way to "cancel" a response.Redirect? For example, in the code
below, could I insert anything in the Catch statement that would cancel the
redirect and resume flow after the try-catch?

Try
Response.Redirect(strPage)
Catch ex1 As Threading.ThreadAbortException
ex1 = ex1
'Cancel Respone here
End Try
'Resume flow here

I am trying to write unit tests for pages that include Redirects.

Thanks for any advice,
Tim
Nov 18 '05 #1
13 4653
What is it you expect to catch from a Response.Redirect() ?
I suggest you look at a sample of validating a URL instead of the try/catch
on the redirect

--
Curt Christianson
Owner/Lead Developer, DF-Software
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"Tim" <Ti*@discussions.microsoft.com> wrote in message
news:6F**********************************@microsof t.com...
Hello,
Is there a way to "cancel" a response.Redirect? For example, in the code
below, could I insert anything in the Catch statement that would cancel
the
redirect and resume flow after the try-catch?

Try
Response.Redirect(strPage)
Catch ex1 As Threading.ThreadAbortException
ex1 = ex1
'Cancel Respone here
End Try
'Resume flow here

I am trying to write unit tests for pages that include Redirects.

Thanks for any advice,
Tim

Nov 18 '05 #2
Tim
Hello Curt,
I'm trying to "catch" that the page being tested correctly tried to
Redirect to another page.

Can you provide an article that discusses further validating a URL - I'm not
seeing how this would help unit test the page.

Thanks,
Tim

"Curt_C [MVP]" wrote:
What is it you expect to catch from a Response.Redirect() ?
I suggest you look at a sample of validating a URL instead of the try/catch
on the redirect

--
Curt Christianson
Owner/Lead Developer, DF-Software
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"Tim" <Ti*@discussions.microsoft.com> wrote in message
news:6F**********************************@microsof t.com...
Hello,
Is there a way to "cancel" a response.Redirect? For example, in the code
below, could I insert anything in the Catch statement that would cancel
the
redirect and resume flow after the try-catch?

Try
Response.Redirect(strPage)
Catch ex1 As Threading.ThreadAbortException
ex1 = ex1
'Cancel Respone here
End Try
'Resume flow here

I am trying to write unit tests for pages that include Redirects.

Thanks for any advice,
Tim


Nov 18 '05 #3
Response.Redirect accepts two parameters the second being to abort the
current thread or continue with execution. Maybe look into that, it might
help your cause.
Enrique.
"Tim" <Ti*@discussions.microsoft.com> wrote in message
news:6F**********************************@microsof t.com...
Hello,
Is there a way to "cancel" a response.Redirect? For example, in the code
below, could I insert anything in the Catch statement that would cancel
the
redirect and resume flow after the try-catch?

Try
Response.Redirect(strPage)
Catch ex1 As Threading.ThreadAbortException
ex1 = ex1
'Cancel Respone here
End Try
'Resume flow here

I am trying to write unit tests for pages that include Redirects.

Thanks for any advice,
Tim

Nov 18 '05 #4
What are you trying to "test"? If the page is there or some processing that
happens on the page?
I mean when you Response.Redirect() there is NO return value, it always
executes, there is nothing to try/catch.

--
Curt Christianson
Owner/Lead Developer, DF-Software
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"Tim" <Ti*@discussions.microsoft.com> wrote in message
news:41**********************************@microsof t.com...
Hello Curt,
I'm trying to "catch" that the page being tested correctly tried to
Redirect to another page.

Can you provide an article that discusses further validating a URL - I'm
not
seeing how this would help unit test the page.

Thanks,
Tim

"Curt_C [MVP]" wrote:
What is it you expect to catch from a Response.Redirect() ?
I suggest you look at a sample of validating a URL instead of the
try/catch
on the redirect

--
Curt Christianson
Owner/Lead Developer, DF-Software
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"Tim" <Ti*@discussions.microsoft.com> wrote in message
news:6F**********************************@microsof t.com...
> Hello,
> Is there a way to "cancel" a response.Redirect? For example, in the
> code
> below, could I insert anything in the Catch statement that would cancel
> the
> redirect and resume flow after the try-catch?
>
> Try
> Response.Redirect(strPage)
> Catch ex1 As Threading.ThreadAbortException
> ex1 = ex1
> 'Cancel Respone here
> End Try
> 'Resume flow here
>
> I am trying to write unit tests for pages that include Redirects.
>
> Thanks for any advice,
> Tim


Nov 18 '05 #5
Tim
I'm trying to write a unit test to check (1) if page correctly does a
Redirect, (2) Ideally check the value of the page it's trying to redirect to.

Response .Redirect doesn't have a return value, but it does have an affect
--> navigating to a new page. I'm trying to test that the page was about to
do the correct affect (navigate to the new page), and then I want to cancel
that so the main host program can still run all the other tests.

It's seeming like this is very non-standard, and I'll try to find a more
standard approach.

Tim

"Curt_C [MVP]" wrote:
What are you trying to "test"? If the page is there or some processing that
happens on the page?
I mean when you Response.Redirect() there is NO return value, it always
executes, there is nothing to try/catch.

--
Curt Christianson
Owner/Lead Developer, DF-Software
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"Tim" <Ti*@discussions.microsoft.com> wrote in message
news:41**********************************@microsof t.com...
Hello Curt,
I'm trying to "catch" that the page being tested correctly tried to
Redirect to another page.

Can you provide an article that discusses further validating a URL - I'm
not
seeing how this would help unit test the page.

Thanks,
Tim

"Curt_C [MVP]" wrote:
What is it you expect to catch from a Response.Redirect() ?
I suggest you look at a sample of validating a URL instead of the
try/catch
on the redirect

--
Curt Christianson
Owner/Lead Developer, DF-Software
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"Tim" <Ti*@discussions.microsoft.com> wrote in message
news:6F**********************************@microsof t.com...
> Hello,
> Is there a way to "cancel" a response.Redirect? For example, in the
> code
> below, could I insert anything in the Catch statement that would cancel
> the
> redirect and resume flow after the try-catch?
>
> Try
> Response.Redirect(strPage)
> Catch ex1 As Threading.ThreadAbortException
> ex1 = ex1
> 'Cancel Respone here
> End Try
> 'Resume flow here
>
> I am trying to write unit tests for pages that include Redirects.
>
> Thanks for any advice,
> Tim


Nov 18 '05 #6
Tim
Thanks - but that would require me to change the original page that is being
tested, which I cannot do. All my code is limited to the unit-test that calls
the page.

Tim

"Enrique Santa Cruz" wrote:
Response.Redirect accepts two parameters the second being to abort the
current thread or continue with execution. Maybe look into that, it might
help your cause.
Enrique.
"Tim" <Ti*@discussions.microsoft.com> wrote in message
news:6F**********************************@microsof t.com...
Hello,
Is there a way to "cancel" a response.Redirect? For example, in the code
below, could I insert anything in the Catch statement that would cancel
the
redirect and resume flow after the try-catch?

Try
Response.Redirect(strPage)
Catch ex1 As Threading.ThreadAbortException
ex1 = ex1
'Cancel Respone here
End Try
'Resume flow here

I am trying to write unit tests for pages that include Redirects.

Thanks for any advice,
Tim


Nov 18 '05 #7
That might be best. It's one of those cases where you can't test. I mean you
dont know if it worked till it's on the new page, and at that point the
calling page isn't active anymore.... kind of like testing to see if a gun
fires by firing it... to late to get the bullet back in the gun afterwards.

--
Curt Christianson
Owner/Lead Developer, DF-Software
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"Tim" <Ti*@discussions.microsoft.com> wrote in message
news:9C**********************************@microsof t.com...
I'm trying to write a unit test to check (1) if page correctly does a
Redirect, (2) Ideally check the value of the page it's trying to redirect
to.

Response .Redirect doesn't have a return value, but it does have an affect
--> navigating to a new page. I'm trying to test that the page was about
to
do the correct affect (navigate to the new page), and then I want to
cancel
that so the main host program can still run all the other tests.

It's seeming like this is very non-standard, and I'll try to find a more
standard approach.

Tim

"Curt_C [MVP]" wrote:
What are you trying to "test"? If the page is there or some processing
that
happens on the page?
I mean when you Response.Redirect() there is NO return value, it always
executes, there is nothing to try/catch.

--
Curt Christianson
Owner/Lead Developer, DF-Software
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"Tim" <Ti*@discussions.microsoft.com> wrote in message
news:41**********************************@microsof t.com...
> Hello Curt,
> I'm trying to "catch" that the page being tested correctly tried to
> Redirect to another page.
>
> Can you provide an article that discusses further validating a URL -
> I'm
> not
> seeing how this would help unit test the page.
>
> Thanks,
> Tim
>
> "Curt_C [MVP]" wrote:
>
>> What is it you expect to catch from a Response.Redirect() ?
>> I suggest you look at a sample of validating a URL instead of the
>> try/catch
>> on the redirect
>>
>> --
>> Curt Christianson
>> Owner/Lead Developer, DF-Software
>> Site: http://www.Darkfalz.com
>> Blog: http://blog.Darkfalz.com
>>
>>
>> "Tim" <Ti*@discussions.microsoft.com> wrote in message
>> news:6F**********************************@microsof t.com...
>> > Hello,
>> > Is there a way to "cancel" a response.Redirect? For example, in the
>> > code
>> > below, could I insert anything in the Catch statement that would
>> > cancel
>> > the
>> > redirect and resume flow after the try-catch?
>> >
>> > Try
>> > Response.Redirect(strPage)
>> > Catch ex1 As Threading.ThreadAbortException
>> > ex1 = ex1
>> > 'Cancel Respone here
>> > End Try
>> > 'Resume flow here
>> >
>> > I am trying to write unit tests for pages that include Redirects.
>> >
>> > Thanks for any advice,
>> > Tim
>>
>>
>>


Nov 18 '05 #8
Just comment out the redirect, and write an entry to the event log, text
file or database instead.

Jeff
"Tim" <Ti*@discussions.microsoft.com> wrote in message
news:41**********************************@microsof t.com...
Hello Curt,
I'm trying to "catch" that the page being tested correctly tried to
Redirect to another page.

Can you provide an article that discusses further validating a URL - I'm not seeing how this would help unit test the page.

Thanks,
Tim

"Curt_C [MVP]" wrote:
What is it you expect to catch from a Response.Redirect() ?
I suggest you look at a sample of validating a URL instead of the try/catch on the redirect

--
Curt Christianson
Owner/Lead Developer, DF-Software
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"Tim" <Ti*@discussions.microsoft.com> wrote in message
news:6F**********************************@microsof t.com...
Hello,
Is there a way to "cancel" a response.Redirect? For example, in the code below, could I insert anything in the Catch statement that would cancel the
redirect and resume flow after the try-catch?

Try
Response.Redirect(strPage)
Catch ex1 As Threading.ThreadAbortException
ex1 = ex1
'Cancel Respone here
End Try
'Resume flow here

I am trying to write unit tests for pages that include Redirects.

Thanks for any advice,
Tim


Nov 18 '05 #9
Tim - just curious what / how you are testing the page. With some sort
of HTTP client? Could you look for the 302 redirect response code?

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Thu, 4 Nov 2004 12:40:02 -0800, Tim <Ti*@discussions.microsoft.com>
wrote:
Thanks - but that would require me to change the original page that is being
tested, which I cannot do. All my code is limited to the unit-test that calls
the page.

Tim


Nov 18 '05 #10
Tim
Hey Scott,
I have another class in a web application that calls that page like:
WebForm1 p = new WebForm1();
p.SomeMethodOnWebForm1();

Tim
"Scott Allen" wrote:
Tim - just curious what / how you are testing the page. With some sort
of HTTP client? Could you look for the 302 redirect response code?

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Thu, 4 Nov 2004 12:40:02 -0800, Tim <Ti*@discussions.microsoft.com>
wrote:
Thanks - but that would require me to change the original page that is being
tested, which I cannot do. All my code is limited to the unit-test that calls
the page.

Tim


Nov 18 '05 #11
So you want to change the behavior of the page without changing anything in
the page?

Why can't you change the page? Did you write it? Can you "talk" to the
developers??

Jeff
"Tim" <Ti*@discussions.microsoft.com> wrote in message
news:E4**********************************@microsof t.com...
Hey Scott,
I have another class in a web application that calls that page like:
WebForm1 p = new WebForm1();
p.SomeMethodOnWebForm1();

Tim
"Scott Allen" wrote:
Tim - just curious what / how you are testing the page. With some sort
of HTTP client? Could you look for the 302 redirect response code?

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Thu, 4 Nov 2004 12:40:02 -0800, Tim <Ti*@discussions.microsoft.com>
wrote:
Thanks - but that would require me to change the original page that is beingtested, which I cannot do. All my code is limited to the unit-test that callsthe page.

Tim


Nov 18 '05 #12
Tim
> So you want to change the behavior of the page without changing anything in
the page? No - I want the page to produce the same effect (send an "output" to try to
redirect to another page), but I want to trap that "output" and prevent it
from actually redirecting.

I can't comment out the redirects, but I could have the redirects abstracted
to a method that returns a string, and then I could check the string value to
make sure it's correct.

I can talk to the developers.

Tim

"Jeff Dillon" wrote:
So you want to change the behavior of the page without changing anything in
the page?

Why can't you change the page? Did you write it? Can you "talk" to the
developers??

Jeff
"Tim" <Ti*@discussions.microsoft.com> wrote in message
news:E4**********************************@microsof t.com...
Hey Scott,
I have another class in a web application that calls that page like:
WebForm1 p = new WebForm1();
p.SomeMethodOnWebForm1();

Tim
"Scott Allen" wrote:
Tim - just curious what / how you are testing the page. With some sort
of HTTP client? Could you look for the 302 redirect response code?

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Thu, 4 Nov 2004 12:40:02 -0800, Tim <Ti*@discussions.microsoft.com>
wrote:

>Thanks - but that would require me to change the original page that is being >tested, which I cannot do. All my code is limited to the unit-test that calls >the page.
>
>Tim
>


Nov 18 '05 #13
Um..like someone said earlier??

Just comment out the redirect, and write an entry to the event log, text
file or database instead
"Tim" <Ti*@discussions.microsoft.com> wrote in message
news:61**********************************@microsof t.com...
So you want to change the behavior of the page without changing anything in the page? No - I want the page to produce the same effect (send an "output" to try

to redirect to another page), but I want to trap that "output" and prevent it
from actually redirecting.

I can't comment out the redirects, but I could have the redirects abstracted to a method that returns a string, and then I could check the string value to make sure it's correct.

I can talk to the developers.

Tim

"Jeff Dillon" wrote:
So you want to change the behavior of the page without changing anything in the page?

Why can't you change the page? Did you write it? Can you "talk" to the
developers??

Jeff
"Tim" <Ti*@discussions.microsoft.com> wrote in message
news:E4**********************************@microsof t.com...
Hey Scott,
I have another class in a web application that calls that page like:
WebForm1 p = new WebForm1();
p.SomeMethodOnWebForm1();

Tim
"Scott Allen" wrote:

> Tim - just curious what / how you are testing the page. With some sort > of HTTP client? Could you look for the 302 redirect response code?
>
> --
> Scott
> http://www.OdeToCode.com/blogs/scott/
>
> On Thu, 4 Nov 2004 12:40:02 -0800, Tim <Ti*@discussions.microsoft.com> > wrote:
>
> >Thanks - but that would require me to change the original page that
is being
> >tested, which I cannot do. All my code is limited to the unit-test
that calls
> >the page.
> >
> >Tim
> >
>
>


Nov 18 '05 #14

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

Similar topics

3
by: news.public.microsoft.com | last post by:
Hi everyone, I have a VB.NET web form with some field validators and Save and Cancel buttons. What I want to do is on the Cancel button On_Click event, Response.Redirect to another page. The...
3
by: Mvk | last post by:
Hi; I have a simple aspx form. I have put a textbox and 2 buttons on it. The textbox is linked to a requiredfieldvalidator. Click on button 1 (= ok button) = Store value in textbox in...
7
by: theyas | last post by:
How can I get my code to NOT display two "Open/Save/Cancel/More Info" dialog boxes when using the "Response.WriteFile" method to download a file to IE I've asked about this before and didn't get a...
3
by: MB | last post by:
Hi, I am doing a project which uses asp.net to develop its forms. The form uses validation web controls to validate the data entered in text boxes. When Cancel Button is pressed which is to exit...
2
by: wiewiek | last post by:
Is there a way to go back to the previous page when a button (Cancel button) is hot? It's an ASP control. Thanks
3
by: David Thielen | last post by:
Hi; I am guessing how to do this is very easy - but I can't find it anywhere. I have a cancel button on my form and if the user clicks it, I want to perfomr no validation and redirect to a...
4
by: Dabbler | last post by:
I'm trying to code a FormView page to return to the Gridview List if the user clicks the Cancel button while in insert mode but nothing happens with the following code: void...
5
by: venner | last post by:
I'm having an issue with an ASP.NET website after upgrading to ASP.NET 2.0. The website makes use of a central authentication service (CAS) provided at the university I work for. Each page checks...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...

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.