如何阻止ASP.Net发送默认字符集?

And*_*per 5 asp.net webforms content-type iis-7.5

我正在构建一些用于测试各种漏洞场景的网页,但ASP.Net或IIS在保护我自己方面做得非常好.

我正在尝试做的事情之一是使用各种Content-Type标头返回响应,包含和不包含charset声明.问题我,如果我遗漏了charset,那么ASP.Net似乎默认添加utf-8.

在我的ASPX.cs代码隐藏中,如果我有Response.AddHeader("Content-Type", "text/html")或者Page.ContentType = "test/html",我希望看到页面返回以下标题:

Content-Type: text/html
Run Code Online (Sandbox Code Playgroud)

相反,我得到:

Content-Type: text/html; charset=utf-8
Run Code Online (Sandbox Code Playgroud)

如果我使用Response.AddHeader("Content-Type", "text/html; charset=iso-8859-1")然后我得到预期的标题:

Content-Type: text/html; charset=iso-8859-1
Run Code Online (Sandbox Code Playgroud)

charset=utf-8当我不想要它时,有没有办法阻止ASP.Net(IIS?)附加到标题?

我正在使用ASP.Net 4.0和IIS 7.5.

小智 8

试试这个:

Response.Charset = "";
Run Code Online (Sandbox Code Playgroud)