There are only two industries that refer to their customers as "users". --Edward Tufte

What is Request.AcceptTypes in ASP.NET

A little known and little used property of the Request object

Summary

There is a surprising lack of information about the Request.AcceptTypes property and what it's really for.

This property returns a string array of mime types supported by the client browser. For example, "text/html", "application/xml", etc. But what does this really mean? Let's do some experiments.

For the first experiment, we just see what the typical mime types are for a few different browsers. Add the following method to the code-behind of an aspx with a Label on the page called lblOutput.

Method to get and print the AcceptTypes array
private void TestRequestAcceptTypes()
{
   string[] types = Request.AcceptTypes;
   foreach (string type in types)
      lblOutput.Text += type + "<br>";
}

The following represent the page output from the above method for a few different browsers:

Accepted Mime types for Internet Explorer 6.0
*/*
Accepted Mime types for FireFox 1.0 and Netscape 8.0
text/xml
application/xml
application/xhtml+xml
text/html;q=0.9
text/plain;q=0.8
image/png
*/*;q=0.5
Accepted Mime types for Opera 8.5
text/html
application/xml;q=0.9
application/xhtml+xml
image/png
image/jpeg
image/gif
image/x-xbitmap
*/*;q=0.1

You will notice that for all of the above browsers, they each list / to indicate they accept all mime types. And Internet Explorer does not even explicitly list text/html! What's up with that? My version of Firefox supports embedded pdf files, so why isn't that listed among the mime types?

While the mime types may be useful for a few special cases, for example, if a browser says it supports application/xhtml then if you set that as the mime type of the delivered page, then it may have the ability to handle that page better than if the type were just text/html. I really don't know because I haven't encountered a case like this. One reason for that is because any good web developer should develop for all browsers. And besides, to make separate versions of a page for different browsers requires a lot of extra work. I simply use techniques and technologies which all standard browsers can handle nicely.

So my point is this, the published mime types from the client browser are virtually useless to the web developer, so you should ignore them as much as possible until there are consistent standards. That said, I suspect there are a few special cases out there somewhere.

 

Version: 6.0.20200920.1535