views:

128

answers:

2

I have a page which needs to terminate execution of it's code (which is run at render) but not stop the execution of the MasterPage.

The problem is this, page 'Default.aspx' uses the masterpage 'MasterPage1.aspx'. The code in Default.aspx checks a certain condition and if found to be true, Default.aspx needs to stop executing, but render the rest of the MasterPage.

I found that if I call response.end() in default.aspx, the rendering of the MasterPage is also terminated.

So what I am looking for is an alternative which stops execution in default.aspx, but still renders the rest of the MasterPage.

Thanks :)

A: 

Rather than returning a master page without any content, why not use Response.Redirect to go to an error page (which could have the same master page)?

bwarner
Yeah I guess thats a good idea. It would still be nice not to need a redirect, but this works.Thanks
Jack Hayter
A: 

You can use Server.Transfer() to go to a new page, and avoid a redirect.

RickNZ
what is the difference, and how is it an advantage?
Jack Hayter
`Response.Redirect()` sends a redirect HTTP response to the client, which will then request a new page. `Server.Transfer()` tells the server to send a different page to the client, but without requiring another round-trip (no redirect). From the client's perspective, it looks like the same URL (no change in their address bar).
RickNZ