Поделиться через


How to escape {curly brackets} in URL Rewrite rule

There is no escaping character in an URL Rewrite expression, but here is how you include curly bracket within an URL Rewrite expression.

For opening { curly bracket you will always require to use the UrlDecode function to generate the { character from its encoded value %7B, that is:

{UrlDecode:%7B}

For closing } curly bracket you don’t have do anything if the character is not nested in a another URL Rewrite expression; otherwise you need to use UrlDecode with %7D.

{UrlDecode:%7D}

Examples

For generating “Products.aspx?Id={Guid}”, where the Guid comes from a map expression:

“Products.aspx?Id={UrlDecode:%7B}{GuidMap:{R:0}}}”

Note that the last closing curly bracket is written as it is, it doesn’t require to be encoded because there is no opening { bracket that matches, so it is handled as a regular character.

  • {UrlDecode:%7B}
  • {
    • GuidMap:{R:0}
  • }
  • }

When a closing { bracket is nested in another expression you will need to encode it. NameFromGuidMap is a map that requires the input to be formatted as “{GUID}”.

“Products.aspx?Name={NameFromGuidMap:{UrlDecode:%7B}{R:0}{UrlDecode:%7D}}”

  • {
    • NameFromGuidMap:
      • {UrlDecode:%7B}
      • {R:0}
      • {UrlDecode:%7D}
  • }