0

I have a very simple Generic Handler, which sends a simple alert to the client. I set the Content-Type header to be application/x-javascript, but what I get from server is a text/html content type.

Here is the code of my generic handler:

public void ProcessRequest(HttpContext context)
{
    context.Response.Clear();
    context.Response.AddHeader("Content-Type", "application/x-javascript");
    context.Response.ContentType = "application/x-javascript";
    context.Response.Write("alert('javascript is here');");
    context.Response.Flush();
    context.Response.End();
}

Now, when I call this handler, via http://domain/path/handler.ashx, what I get in Firebug is:

enter image description here

Any idea what's wrong?

PS: I want to create a script delivery service, and the script is authored on the fly. That's why I use a dynamic generic handler to serve this script.

Saeed Neamati
  • 35,341
  • 41
  • 136
  • 188

1 Answers1

0

Try clearing the response headers first:

context.Response.ClearHeaders()
...

https://stackoverflow.com/a/7291044

Community
  • 1
  • 1
Kirk B.
  • 456
  • 2
  • 6