473,484 Members | 1,675 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

What about the next statement afeter response.redirect andserver.transfer?

I've seen many people have written code like this:

response.redirect();
return;

or

server.transfer();
return;

I doubt whether the statement "return;" will be hit? I think it's
redundant, isn't it?
Mar 10 '08 #1
7 1236
"lander" <lo************@gmail.comwrote in message
news:8c**********************************@s8g2000p rg.googlegroups.com...
I doubt whether the statement "return;" will be hit? I think it's
redundant, isn't it?
No.
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Mar 10 '08 #2
You right.
return will never bit hit in this case.

But I still always put it for clarity

George.

"lander" <lo************@gmail.comwrote in message
news:8c**********************************@s8g2000p rg.googlegroups.com...
I've seen many people have written code like this:

response.redirect();
return;

or

server.transfer();
return;

I doubt whether the statement "return;" will be hit? I think it's
redundant, isn't it?

Mar 10 '08 #3

"George Ter-Saakov" <gt****@cardone.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
"lander" <lo************@gmail.comwrote in message
news:8c**********************************@s8g2000p rg.googlegroups.com...
>I've seen many people have written code like this:

response.redirect();
return;

or

server.transfer();
return;

I doubt whether the statement "return;" will be hit? I think it's
redundant, isn't it?

You are right.
return will never bit hit in this case.
That's incorrect...

protected void Page_Load(object sender, EventArgs e)
{
if (this == that)
{
Response.Redirect("mypage.aspx", false);
//return;
}

if (this != that)
{
// this *will* run if the above return is not unremmed...
}
}
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Mar 10 '08 #4
Yes, there is a second parameter which will change default behavior.

But default behavior would terminate the execution.

So in
Response.Redirect("mynewpage.aspx")
return;

"return" is unnecessary

George.

"Mark Rae [MVP]" <ma**@markNOSPAMrae.netwrote in message
news:uv**************@TK2MSFTNGP06.phx.gbl...
"George Ter-Saakov" <gt****@cardone.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
>"lander" <lo************@gmail.comwrote in message
news:8c**********************************@s8g2000 prg.googlegroups.com...
>>I've seen many people have written code like this:

response.redirect();
return;

or

server.transfer();
return;

I doubt whether the statement "return;" will be hit? I think it's
redundant, isn't it?

You are right.
return will never bit hit in this case.

That's incorrect...

protected void Page_Load(object sender, EventArgs e)
{
if (this == that)
{
Response.Redirect("mypage.aspx", false);
//return;
}

if (this != that)
{
// this *will* run if the above return is not unremmed...
}
}
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Mar 10 '08 #5
"George Ter-Saakov" <gt****@cardone.comwrote in message
news:uN****************@TK2MSFTNGP04.phx.gbl...
>>You are right.
return will never bit hit in this case.

That's incorrect...

protected void Page_Load(object sender, EventArgs e)
{
if (this == that)
{
Response.Redirect("mypage.aspx", false);
//return;
}

if (this != that)
{
// this *will* run if the above return is not unremmed...
}
}

Yes, there is a second parameter which will change default behavior.

But default behavior would terminate the execution.
Yes, that's true, but that would raise a
System.Threading.ThreadAbortException...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Mar 10 '08 #6
thats generally what you want.

overwise you need to override the render event, set a flag that a redirect
was done, then cancel the render (and maybe prerender). you may need to also
override the event firing logic, as you probably don't want to raise events
after a redirect.

if you don't do this, all the page processing happens, and html is
downloaded to the browser, but ignored because of the redirect header.

-- bruce (sqlwork.com)
"Mark Rae [MVP]" wrote:
"George Ter-Saakov" <gt****@cardone.comwrote in message
news:uN****************@TK2MSFTNGP04.phx.gbl...
>You are right.
return will never bit hit in this case.

That's incorrect...

protected void Page_Load(object sender, EventArgs e)
{
if (this == that)
{
Response.Redirect("mypage.aspx", false);
//return;
}

if (this != that)
{
// this *will* run if the above return is not unremmed...
}
}
Yes, there is a second parameter which will change default behavior.

But default behavior would terminate the execution.

Yes, that's true, but that would raise a
System.Threading.ThreadAbortException...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Mar 10 '08 #7
On 3ÔÂ10ÈÕ, ÏÂÎç11ʱ19·Ö, "Mark Rae [MVP]" <m...@markNOSPAMrae.netwrote:
"George Ter-Saakov" <gt-...@cardone.comwrote in message

news:uN****************@TK2MSFTNGP04.phx.gbl...


>You are right.
return will never bit hit in this case.
That's incorrect...
protected void Page_Load(object sender, EventArgs e)
{
if (this == that)
{
Response.Redirect("mypage.aspx", false);
//return;
}
if (this != that)
{
// this *will* run if the above return is not unremmed...
}
}
Yes, there is a second parameter which will change default behavior.
But default behavior would terminate the execution.

Yes, that's true, but that would raise a
System.Threading.ThreadAbortException...

--
Mark Rae
ASP.NET MVPhttp://www.markrae.net- Òþ²Ø±»ÒýÓÃÎÄ×Ö -

- ÏÔʾÒýÓõÄÎÄ×Ö -
Hi mark, would you pls explain *why* to us? Thanks really.
Mar 13 '08 #8

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

Similar topics

11
2139
by: Stephen | last post by:
I was wondering if someone can help me with an web application design problem. I have a aspx page which builds up an arraylist called addresses and outputs the values in the arraylist items to a...
6
4542
by: \A_Michigan_User\ | last post by:
Ok, I give up... why do 1-4 work fine... but 5-6 give "can't find" errors? 1. Client-side VBscript code: call navigate("\\209.11.22.33\MyDir") 2. Client-side VBscript code: location.href...
4
2086
by: Harsh Thakur | last post by:
Hi, I'd like to know the performance related differences between Response.Redirect and Server.Transfer. I'd like to redirect the user to a different page. I can either do a...
3
5470
by: Alan Silver | last post by:
Hello, Sorry if this is a stupid question, but I can't really see much difference between these tow methods according to the scant info in the SDK. Could anyone enlighten me? TIA -- Alan...
9
1347
by: odwrotnie | last post by:
Hi, what is the difference between Response.Redirect("Stop.aspx"); and Server.Transfer("Stop.aspx"); ? -- Best regards,
5
4544
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...
20
3744
by: Simon Says | last post by:
Hi, I've a login page in which after authenticating it via the Oracle DB, I will stored the user information into the Session. However, when the Session timeout occurs, all of the user...
5
2155
by: phanimadhav | last post by:
Response.Redirect("explain.aspx?firstimportname="+filename); This is my statement.In this statement i am sending only single value to next page.but i want to pass multiple values by using multiple...
3
3507
by: jasonheath.net | last post by:
I apologize in advance for the length of this post. I wanted to get as much detail as possible in here. We have 1 web app that contains the functionality to do some single sign-on logic. The...
0
6950
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...
1
6811
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
7209
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...
0
5403
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,...
0
4527
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...
0
3044
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...
0
3038
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
588
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
234
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.