title: Input validation for .NET web api in Http Get request
body: <p>I am developing a Restful service using .net web API.</p>
  
  <p>There are a few posts about input validation for the post request using model validation. However, I am wondering what is the best practice of doing the validation for Get request.</p>
  
  <p>For example</p>
  
  <pre><code>public HttpResponseMessage Get(int id, string type)
  {
      // validation
      if (id &lt;= 500 &amp; id &gt;= 0) {
          // invalid request
          throw new HttpResponseException();
      }
      // type validation
      if (type is not in a predefined allowed type list from database) {
          // throw validation error
      }
      // more validation ... ...
      // do something else
  }
  </code></pre>
  
  <p>I would like to know what is the best place to put the validation logic in in .net web api framework. </p>
  
  <p><strong>The id validation is just an example and the validation logic could go quite complicated for some cases.</strong> </p>
  
  <p>I don't want to create a class just for the id and put some custom validator attribute on the ID property. I think .net has a better support for that already.</p>