Edentity Web Systems
You solve creative. We crack code.
/Header/WhoWeAre.jpg
 

09/14/2009 Always check for null on Request.UserAgent
Posted by Joel Varty

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 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

« Back to Blog Main Page |

1 Comment(s)

Very nice site!

Leave Comment

Name:
Comment:  
 
Security Check: 
 
 
Edentity Web Systems Inc.
Suite 201
40 Spadina Ave.
Toronto ON
M5V 2H8
Tel:
416.591.2500
Fax:
416.352.5270
Home | Who We Are | What We Do | Clients & Brands | Careers | Contact

Copyright © 2010 Edentity Web Systems Inc. Privacy Policy