0

I made my routes to Persian , cause of that my Url route in StartUp config is like

endpoints.MapControllerRoute(
            name: "HomeController",
            defaults: new { controller = "Home", action = "Test" },
            pattern: $@"تست/خانه");

And it turns into this https://localhost:44377/%D8%AE%D8%A7%D9%86%D9%87/%D8%B5%D9%81%D8%AD%D9%87%20%D8%A7%D8%B5%D9%84%DB%8C in Browser address bar and also when I try to get current request path in controller with Request.HttpContext.Request.Path, it gives me the /%D8%AE%D8%A7%D9%86%D9%87/%D8%B5%D9%81%D8%AD%D9%87%20%D8%A7%D8%B5%D9%84%D part that this is تست/خانه So I need help to convert this /%D8%AE%D8%A7%D9%86%D9%87/%D8%B5%D9%81%D8%AD%D9%87%20%D8%A7%D8%B5%D9%84%D to this => تست/خانه in C# , MVC Core

  • Those characters need to be url escaped: https://stackoverflow.com/questions/7109143/what-characters-are-valid-in-a-url. When you get the request back, is the value correct in c#? – gunr2171 Nov 04 '21 at 15:16

1 Answers1

1

This is url encoded and you need to decode it.

System.Web.HttpUtility.UrlDecode(Request.HttpContext.Request.Path);
Kahbazi
  • 14,331
  • 3
  • 45
  • 76