title: Asp.Net MVC Identify Site via Url
body: <p>I have an application that will support multiple sites. The site will be determined based on the url. </p>
  
  <p>For example 
  <a href="http://myapp/site/abc123/" rel="nofollow noreferrer">http://myapp/site/abc123/</a>...
  and
  <a href="http://myapp/site/xyz123/" rel="nofollow noreferrer">http://myapp/site/xyz123/</a>...</p>
  
  <p>The site code will drive a lot of the functionality for example themes, available modules, etc...</p>
  
  <p>Questions:</p>
  
  <p>1-)I need to validate the site code is valid and if it isn't, it should direct the user to an info page. I was looking at using <a href="http://msdn.microsoft.com/en-us/library/system.web.routing.irouteconstraint.aspx" rel="nofollow noreferrer">IRouteConstraint</a>, is this appropriate? Are there other/better options? </p>
  
  <p>2-)Any gotchas with this approach (using url to identify site)? Is there are better approach?</p>
  
  <p><strong>Solution</strong></p>
  
  <p>I ended up creating a Custom ActionFilter and check the sitecode in the OnActionExecuting event. That seems to work well and fit better than the IRouteConstraint.</p>