简体   繁体   中英

Can't set “Content-Type” in my generic handler

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:

在此处输入图片说明

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.

Try clearing the response headers first:

context.Response.ClearHeaders()
...

https://stackoverflow.com/a/7291044

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM