i have .net core 2.2 web api i upgraded it to "inProcess", client's who call this service with double forward slah got 404, when configure it to "OutOfProcess" it's work just fine. example of the problematic call:
https://mMYApiAddress.co/api/GetSomeData//3
when configure it to "OutOfProcess" it's work just fine.
i want my web api to work "inProcess" configuration and will be able to get calls with double slash as before.
When configuring "OutOfProcess" , Kestrel web server is used to process your requests. In Kestrel web server, spaces or extra strings in the request path are automatically recognized and the path is modified to the correct format.
When configuring "InProcess" ,IIS HTTP Server (IISHttpServer) is used instead of Kestrel server.Requests are processed directly by the application. So you got the 404 response .
You could customize a middleware to rewrite the url like below :
public class RewriteRouteRule
{
public static void ReWriteRequests(RewriteContext context)
{
var request = context.HttpContext.Request;
if (request.Path.Value.Contains("values"))
{
string[] splitlist = request.Path.Value.Split("/");
var newarray = splitlist.Where(s => !string.IsNullOrEmpty(s)).ToArray();
var newpath = "";
foreach (var item in newarray)
{
newpath += "/" + item;
}
request.Path = newpath;
}
}
}
Use the middleware in Configure method of Startup.cs
app.UseRewriter(new RewriteOptions()
.Add(RewriteRouteRule.ReWriteRequests)
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With