PreSendRequestHeaders alternativa en un HttpModule

According to this information given by the Asp.Net team What not to do in no deberías usar PreSendRequestHeaders in a managed HttpModule.

PreSendRequestHeaders and PreSendRequestContext

Recommendation: Do not use these events with managed modules.

The PreSendRequestHeaders and PreSendRequestContext events can be used with native IIS modules, but not with managed modules that implement IHttpModule. Setting these properties can cause issues with asynchronous requests.

This is precisely what I do in my Biblioteca de procesamiento de imágenes to ensure that the correct mime type is sent along with the response.

What would be the recommended alternative approach?

preguntado el 09 de septiembre de 13 a las 22:09

Should have used the absolute link. Code is long gone now using PostReleaseRequestState preferiblemente.… -

2 Respuestas

In a handler for BeginRequest, Utilizar HttpResponse.AddOnSendingHeaders to subscribe a handler for that event.

This is essentially the same thing as PreSendRequestHeaders, however it is handled fully within the ASP.NET pipeline so it doesn't have the same problems with the native/managed interface that PreSendRequestHeaders hace.

Respondido el 21 de diciembre de 17 a las 15:12

Si nos fijamos en el HttpApplication pipeline on MSDN's ASP.NET App Life Cycle page you'll find PreSendRequestHeaders y PreSendRequestContent events at the very bottom. Now that they're suggesting we not use these in managed IHttpModules, the next closest event in the pipeline would be EndRequest, which is deterministic unlike PreSendRequest* events.

I haven't been able to find any information on what the preferred practice is now for specifying response headers, but this will work for you.

Respondido 21 Abr '14, 18:04

Too bad, this won't work. EndRequest is too late, it will result in an exception. See… - Juliano

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.