I want to replace all ۱ chars with 1 in my web api .Net Core requests?
e.g:
Number ۱ should convert to Number 1
In MVC 5 I used HttpModule, in .net core I used Middleware as follows:
namespace VistaBest.Api
{
public class PersianCharsMiddleware
{
private readonly RequestDelegate _next;
public PersianCharsMiddleware(RequestDelegate next)
{
_next = next;
}
public Task Invoke(HttpContext httpContext)
{
var collection = httpContext.Request.Form;
foreach (var controlKey in collection.Keys.Where(controlKey => !controlKey.StartsWith("__")))
{
collection[controlKey] = collection[controlKey].ToString().Replace("۱", "1");
}
return _next(httpContext);
}
}
public static class PersianCharsMiddlewareExtensions
{
public static IApplicationBuilder UsePersianCharsMiddleware(this IApplicationBuilder builder)
{
return builder.UseMiddleware<PersianCharsMiddleware>();
}
}
}
But collection[controlKey] is Readonly and I can't assign value to it?
Actually, I have to edit all string fields of form, How should I do it?
Can I do it with custom model binder?