I have built an asp.net page that returns an image with Response.BinaryWrite()
. This works fine but I have the following quesion.
I call Response.BinaryWrite()
in the Page_PreLoad-event. I expect, that asp.net continues with the "normal" execution of the page till to Unload
event, doing a lot of stuff that is no more necessary because all desired operation is already 开发者_运维问答done. Am I right, and if yes, is there a possibility to tell asp.net that further processing is no more necessary for the page.
Update:
Thanks for all the answers. As suggested, I have used an ASHX-Handler, it was excactly what I needed. Thanks to all and +1 for all answers of this direction. For all who have the same question as I, the link from David Stratton shows a very simple way of how to do it.
Application.CompleteRequest()
would do that for you.
Causes ASP.NET to bypass all events and filtering in the HTTP pipeline chain of execution and directly execute the EndRequest event.
It can be accessed from a Page
class this way:
Context.ApplicationInstance.CompleteRequest();
However, if you want to only return an image, you should be creating a HTTP handler (class that implements IHttpHandler
) and not be using a Page
. See this MSDN article about creating HTTP handlers.
You are right. But you should not be using a Page
to return an image. Use an HttpHandler instead.
use IHttpHandler instead of page
You're looking for Response.End()
.
However, since you aren't using the ASPX featureset, you should move your code to an ASHX handler, which doesn't do any of the things you're trying to avoid in the first place.
You then wouldn't need Response.End
, and you'd get better performance too.
This is not a direct answer to your question, but you can change the page to be an ashx http handler to get rid of the overhead of the page lifecycle if that's what you're really trying to do.
http://support.microsoft.com/kb/308001
精彩评论