Saechel
Saechel

Reputation: 152

How do I handle slash on web.config rewrite

How do I handle product id with slash.

Sample product id: PRODTSP/10

This causes a page error :

"The page cannot be displayed because an internal server error has occurred."

I also tried putting this escaped string to URL, but still the error occurred: PRODTSP%2F10

This is my current configuration:

<rewrite url="^~/Product/id/([^/\\\'=]+)(/?)$" to="~/View/Product.aspx?id=$1" 
permanent="true" processing="stop"/>

Thank you

Upvotes: 1

Views: 169

Answers (1)

Tonned
Tonned

Reputation: 296

<rewrite url="^~/Product/id/([^/\\\'=]+)/?$" to="~/View/Product.aspx?id=$1" permanent="true" processing="stop"/>
<rewrite url="^~/Product/id/([^\\\'=]+)/$" to="~/View/Product.aspx?id=$1" permanent="true" processing="stop"/>
<rewrite url="^~/Product/id/([^\\\'=]+)$" to="~/View/Product.aspx?id=$1" permanent="true" processing="stop"/>

Please try to add this configuration to handle the error.

  • The first line is your original code.
  • The second will handle slash inside the product id and also at the end of the URL.
  • The last will handle slash inside the product id and without slash at the end of the URL.

Upvotes: 2

Related Questions