Andrew Cooper
Andrew Cooper

Reputation: 32586

How do I prevent ASP.Net from sending a default charset?

I'm working on building some web pages for testing various vulnerability scenarios, but ASP.Net, or IIS, is doing too good a job of protecting me from myself.

One of the things I'm trying to do is return responses with various Content-Type headers, with and without charset declarations. The problem I that if I leave out the charset, then ASP.Net seems to add in utf-8 by default.

In my ASPX.cs code-behind, if I have Response.AddHeader("Content-Type", "text/html") or Page.ContentType = "test/html", I would expect to see the following header returned by the page:

Content-Type: text/html

Instead I get:

Content-Type: text/html; charset=utf-8

If I use Response.AddHeader("Content-Type", "text/html; charset=iso-8859-1") then I get the expected header:

Content-Type: text/html; charset=iso-8859-1

Is there a way to stop ASP.Net (IIS?) from appending charset=utf-8 to the header when I don't want it?

I'm using ASP.Net 4.0 and IIS 7.5.

Upvotes: 5

Views: 1424

Answers (1)

IT63
IT63

Reputation: 121

Try this:

Response.Charset = "";

Upvotes: 8

Related Questions