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

L

lander

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?
 
G

George Ter-Saakov

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

But I still always put it for clarity

George.
 
M

Mark Rae [MVP]

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...
}
}
 
G

George Ter-Saakov

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.
 
M

Mark Rae [MVP]

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...
 
B

bruce barker

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)
 
L

lander

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.
 

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

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,527
Members
44,998
Latest member
MarissaEub

Latest Threads

Top