Cambia Research - Supporting the Microsoft .NET Developer Community Supporting the Microsoft .NET Developer Community  

     | Home  | Articles  | Categories  | Coders  | Search  | Submit  | Contact Us    
When you start off by telling those who disagree with you that they are not merely in error but in sin, how much of a dialogue do you expect? --Thomas Sowell

Share Your Knowledge! -- Create and submit your articles the easy way with WebWriter.

Updated:12:55 AM CT Jan 10, 2007
Posted:11:16 PM CT Jan 09, 2007

What is Request.AcceptTypes in ASP.NET

A little known and little used property of the Request object

Author: Steve Lautenschlager

C#.NETASP.NETBrowsersClient SideSite DesignWeb

 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.

Add New Comment
What is Request.AcceptTypes in ASP.NET
Pete27 Mar 07, 10:02Reply 
re: What is Request.AcceptTypes in ASP.NET
Steve Lautenschlager27 Mar 07, 21:04Reply 
CR Comments by Cambia Research
advertisement
 
Steve Lautenschlager (steve)
Steve is the founder and creator of Cambia Research. Developing and maintaining the site combines his passions for technology, writing and education.
Steve holds a Ph.D. in particle physics from Duke University, has worked at CERN, the European center for particle physics (where the web was born) and in Microsoft's web division with microsoft.com, msnbc.com and other web properties. Steve is a web consultant specializing in Microsoft.NET technologies. Read more here.


 
Copyright © Cambia Research 2002-2007. All Rights Reserved. steve [ at ] cambiaresearch.com