views:

106

answers:

0

Hello,

I'm developing an IHttpHandler in an ASP.NET MVC project and I want it to be as fast as possible.

I've read that using HttpWorkerRequest was much more efficient than getting/setting data directly from the HttpContext object because it bypasses all the checks/conversions/encapsulations done by the framework.

It works pretty well but I'm having an issue setting the Referer in my header's response using the following code:

worker.SendKnownResponseHeader(HttpWorkerRequest.HeaderReferer, "http://www.dummy.com");

It throws an ArgumentOutOfRange exception...

Looking into Reflector, I've found out that only IIS7WorkerRequest is checking for the index to be between 1 and 30

public override void SendKnownResponseHeader(int index, string value)
{
    if ((index < 0) || (index >= 30))
        throw new ArgumentOutOfRangeException("index");
    this.SetKnownResponseHeader(index, value, false);
}

Indeed HttpWorkerRequest.HeaderReferer is equal to 36...

So my question is: Should I use instead the SendUnknowResponseHeader function or sets the Referer using Response.AddHeader ?