Search code examples
asp.netmodel-view-controllerasp.net-core-mvcasp.net-core-2.0

.net core , how to handle route with extra leading slash


I need to handle an incoming request which is of the form: //ohif/study/1.1/series Note the exta slash at the front

My controller signature is:

[Route("ohif/study/{studyUid}/series")]
[HttpGet]
public IActionResult GetStudy(string studyUid)

If I modify the incoming request to /ohif/study/1.1/series it works fine

however when I use //ohif/study/1.1/series, the route is not hit

Additionally I also tried: [Route("/ohif/study/{studyUid}/series")] and [Route("//ohif/study/{studyUid}/series")]

Both fail. I unfortunately cannot change the incoming request as it is from an external application. Is there some trick to handle this route? I am working in .NET Core 3.0.

Update NOTE: I have logging activated and I see that asp.net core is analyzing the route, I have the message: No candidates found for the request path '//ohif/study/1.1/series' for the logger Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware


Solution

  • Rewrite the URL at the web server-level, e.g. for IIS, you can use the URL Rewrite Module to automatically redirect //ohif/study/1.1/series to /ohif/study/1.1/series. This isn't a job for your application.