0

What is the right approach for url attributes decoding from HTTP GET requests like:

Get /reports/{categories}/date/{date}

[Route("reports/{categories}/date/{date}")]
public IEnumerable<Report> GetReports(string categories, string date)

Categories is something like Category1\SubCategory, it contains a backslash.

From Swagger, I am getting: Category1\\SubCategory

From a third-party client, I get: Category1%5CSubCategory

Swagger for some reason adds additional backslashes for escaping and third-party client is doing url encoding.

Is there a setting in ASP.NET Core 6, 7 to control the behaviour of parameters regarding special character and encoding?

user007
  • 1,122
  • 1
  • 10
  • 30
  • Anything is good if it works. What is your problem? Do you have any error? – Serge Dec 08 '22 at 03:29
  • Since this is about an **URL** in your code, I would expect that **URL encoding** (like in your third-party client) is the proper way to go. – marc_s Dec 08 '22 at 05:54
  • 1
    Issue is the one already raised long time ago but never fixed, might be in .net 8: https://github.com/dotnet/aspnetcore/issues/11544 I can manually HttpUtility.UrlDecode SubCategory but Framework should be handling this. Application is ported to .Net 7 and Kastrel from IIS where it used to have rules in web.config for handling special characters. https://learn.microsoft.com/en-us/iis/extensions/url-rewrite-module/creating-rewrite-rules-for-the-url-rewrite-module https://stackoverflow.com/questions/46103306/how-to-handle-special-characters-in-web-config-rewrite-rule – user007 Dec 09 '22 at 04:38
  • yes agree with you, but before framework handle it, we can only handle it by code-self – Tiny Wang Dec 09 '22 at 06:24

0 Answers0