Iv’e created a generic handler (.ashx) to handle some simple input from some dropdowns in a html page. I know I should check the data to make sure it’s valid and so I created the following code
string ProjectNumber = context.Request.Form["JobNumber"];
string ProjectShare = context.Request.Form["ProjectShare"];
if (ProjectNumber == null || ProjectNumber == string.Empty) {
throw new Exception("Project number cannot be empty or null");
}
if (ProjectShare == null || ProjectShare == string.Empty) {
throw new Exception("Project Share cannot be empty or null");
}
Is there a better way to handle this input
You could use the
System.String.IsNullOrEmpty()method and ensure you have client side/js validation that executes before passing the data to the handler.