Write entire page from code behind

G

Guest

Hi;

I have a page where the file.aspx.cs Page_Load() method writes the entire
contents out directly. I use this to write a pdf or rtf file as the web page
to display.

In .net 1.1 the way I did this was:
Response.ContentType = contentType;
Response.BinaryWrite(((MemoryStream)proc.GetReport()).ToArray());
Response.End();
return;

This does display the page, but the call to Response.End() throws a
ThreadAbortException. What am I doing wrong?
 
B

Bruce Barker

nothing. Response.End() works by aborting the current thread, to stop
furthor processimng. don't catch this error.

-- bruce (sqlwork.com)
 
G

Guest

Hi;

Is there a way to do this without an exception? I really dislike exceptions
in the happy path.
 
G

Guest

Hi;

If I make it the last line of code in my method, then no exception. Is that
by design? And if so, that's the solution.
 
S

Steven Cheng[MSFT]

Hey Dave,

Bruce is right , there is no problem here. Just a by design behavior
because manually end asp.net response need to abort the current working
thread... Just not catch this exception or if you've used try-catch ..
block, ignore it....

thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| Thread-Topic: Write entire page from code behind
| thread-index: AcYBFaxmJzKPFxOZT0KhA0PS384ikQ==
| X-WBNR-Posting-Host: 199.45.247.98
| From: "=?Utf-8?B?RGF2aWQgVGhpZWxlbg==?=" <[email protected]>
| References: <[email protected]>
<[email protected]>
| Subject: Re: Write entire page from code behind
| Date: Wed, 14 Dec 2005 17:20:02 -0800
| Lines: 39
| Message-ID: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSFTNGXA03.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet:364979
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Hi;
|
| If I make it the last line of code in my method, then no exception. Is
that
| by design? And if so, that's the solution.
|
| --
| thanks - dave
|
|
| "Bruce Barker" wrote:
|
| > nothing. Response.End() works by aborting the current thread, to stop
| > furthor processimng. don't catch this error.
| >
| > -- bruce (sqlwork.com)
| >
| > | > > Hi;
| > >
| > > I have a page where the file.aspx.cs Page_Load() method writes the
entire
| > > contents out directly. I use this to write a pdf or rtf file as the
web
| > > page
| > > to display.
| > >
| > > In .net 1.1 the way I did this was:
| > > Response.ContentType = contentType;
| > > Response.BinaryWrite(((MemoryStream)proc.GetReport()).ToArray());
| > > Response.End();
| > > return;
| > >
| > > This does display the page, but the call to Response.End() throws a
| > > ThreadAbortException. What am I doing wrong?
| > >
| > > --
| > > thanks - dave
| >
| >
| >
|
 

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,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top