Always check for null on Request.UserAgent…
Personally, I love the “Browser Capabilities” project on codeplex (http://browserdetection.codeplex.com/) that does a nice job of extracting the actual things that a browser can do, saving you from doing things the following:
if (Request.UserAgent.IndexOf("AppleWebKit") > 0)
{
//DO SOMETHING
}
But if you find yourself in a situation where you have custom logic you need to implement around a piece of logic (like I did with a mobile site I recently worked on), rememeber to always do a null check on the UserAgent before performing string operations on it.
While you’re at it, please don’t do these things either (I won’t say why not – if you don’t know why not, ask somebody):
Request.QueryString["page"].ToString();
DataRow["column"].ToString();
More later - joel