title: How to allow URLs to contain dots in ASP.NET MVC5?
body: <p>I am working on a website that should allow dots in URLs, like <code>www.mysite.com/somedata/my.name-123</code>.
  My desired behaviour is to make that url equivalent to <code>www.mysite.com/somedata/myname-123</code>, but instead I am getting 404 errors because those dots make IIS try to find a static file. A similar question can be found <a href="https://stackoverflow.com/questions/11728846/dots-in-url-causes-404-with-asp-net-mvc-and-iis">here</a>, but the proposed solutions do not work in my case, as I explain below. This is what I have tried:</p>
  
  <ul>
  <li><p>Adding a new handler like suggested <a href="https://stackoverflow.com/a/12151501/1312524">in the answer accepted in the old question</a> does not work because I need this to work for several paths. If I set path="*" then all static files (for example .css files) fail. I can specify a url pattern using RegEx, but the path attribute does not allow it as far as I know (only wildcards are allowed)</p></li>
  <li><p>Using lines like <code>&lt;httpRuntime relaxedUrlToFileSystemMapping="true" /&gt;</code> and <code>&lt;requestFiltering allowDoubleEscaping="true"/&gt;</code> to the web.config simply doesn't work in MVC5.</p></li>
  <li><p>Adding <code>&lt;modules runAllManagedModulesForAllRequests="true"&gt;</code> to the system.webServer section in the web.config does actually work but this practice is discouraged for many reasons, exposed <a href="http://www.hanselman.com/blog/BackToBasicsDynamicImageGenerationASPNETControllersRoutingIHttpHandlersAndRunAllManagedModulesForAllRequests.aspx" rel="nofollow noreferrer">in this article</a>, so I am trying to avoid this approach if possible.</p></li>
  <li><p>Appending a trailing slash (/) to the URL also solves the problem, but doing so would lead Google to think that I am serving duplicate content, so I cannot use this solution.</p></li>
  </ul>
  
  <p>I cannot think of any other alternatives. Ideally I would like to add a new handler and make it work for all URLs except those ending with certain patterns (.css, .js).</p>
  
  <hr>
  
  <p><strong>UPDATE:</strong>
  I have found a solution that works for me. I will try to explain the steps I took:</p>
  
  <p>First of all, I found a really good explanation of why this behaviour is happening: <a href="http://weblogs.asp.net/owscott/handing-mvc-paths-with-dots-in-the-path" rel="nofollow noreferrer">Scott Forsyth's blog</a>. Some of the solutions listed above are also discussed. After rading the article I decided to handle dotted urls with a rewrite rule. Instead of adding a trailing slash I decided to serve the url without the troublesome dots and then check what the user is looking for in the controller of my application. My base rule looks like this one:</p>
  
  <pre><code>&lt;rule name="remove troublesome dots" stopProcessing="false"&gt;
      &lt;match url="^(.*)\.(\S*)$" /&gt;
      &lt;conditions&gt;
          &lt;add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /&gt;
          &lt;add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /&gt;
      &lt;/conditions&gt;
      &lt;action type="Rewrite" url="{R:1}{R:2}" /&gt;
  &lt;/rule&gt;
  </code></pre>
  
  <p>Note that dots are removed one at a time, so urls with several dots will hit this rule several time. This is bad if urls are likely to have a large number of dots.</p>
  
  <p>If a static file path does not map directly it's disk location, my approach will make it crash. To avoid problems, we need to add exceptions to the remove dots rule for the file endings we need. Seb Nilsson explains how to do it <a href="http://sebnilsson.com/c985a7fd/iis-url-rewrite-rules-skipping-files-types/" rel="nofollow noreferrer">in this blog post</a>, under the "Adding conditions for specific file-endings" section.</p>