简体   繁体   English

无法在我的通用处理程序中设置“ Content-Type”

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

I have a very simple Generic Handler , which sends a simple alert to the client. 我有一个非常简单的Generic Handler ,它向客户端发送了一个简单的警报。 I set the Content-Type header to be application/x-javascript , but what I get from server is a text/html content type. 我将Content-Type标头设置为application/x-javascript ,但是从服务器获得的是text/html内容类型。

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: 现在,当我通过http://domain/path/handler.ashx调用此处理程序时,在Firebug中得到的是:

在此处输入图片说明

Any idea what's wrong? 知道有什么问题吗?

PS: I want to create a script delivery service, and the script is authored on the fly. PS:我想创建一个脚本交付服务,并且脚本是动态编写的。 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 https://stackoverflow.com/a/7291044

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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