bet bet -4 years ago 94
C# Question

Route parameter with slash "/" in URL

I know you can apply a wildcard in the route attribute to allow

such as date input for example:


The problem with wildcard is only applicable to the last paramter in URI. How do I solve the issue if want to have the following URI:



I know there are few options to solve the issue by refactoring the code so please do not offer a solution something like:

  1. change the route template to

  2. change the date to a different format (e.g.

Answer Source

@bet.. I think the genericUriParserOptions is no longer applicable to .net 4.5 or later..

also as suggested by @JotaBe, you might need to correctly decode the url request. In most case the %2F will be automatically translated to a slash '/' so if you need to escape it you will need to decode the '%' char in the first place.. so your URL: will look something like:

Notice the characters '%252F' will be translated to the actual '%2F'


Ok here is the complete solution (Tried it and working for me):

  1. Assuming you have an API endpoint like so:

    public HttpResponseMessage Get(string date)
  2. In the web.config you will need to set the requestPathInvalidCharacters to empty which tells the to allow all request

        <httpRuntime targetFramework="4.5" requestPathInvalidCharacters=""/>                
          <requestFiltering allowDoubleEscaping="true" />
  3. When the client sending the request to the API you will need to make sure to escape the '%' like so:

  4. You then need to decode the request

    public HttpResponseMessage Get(string date)
            DateTime actualDate = DateTime.Parse(System.Net.WebUtility.UrlDecode(date)); // date is 23/06/2015
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download