she*_*ira 5 asp.net model-view-controller asp.net-core-mvc asp.net-core-2.0
我需要处理以下形式的传入请求: //ohif/study/1.1/series 请注意前面的额外斜杠
我的控制器签名是:
[Route("ohif/study/{studyUid}/series")]
[HttpGet]
public IActionResult GetStudy(string studyUid)
Run Code Online (Sandbox Code Playgroud)
如果我将传入请求修改为 /ohif/study/1.1/series 它工作正常
但是,当我使用 //ohif/study/1.1/series 时,路线未被命中
另外我还尝试了: [Route("/ohif/study/{studyUid}/series")] 和 [Route("//ohif/study/{studyUid}/series")]
两者都失败了。不幸的是,我无法更改传入的请求,因为它来自外部应用程序。有什么技巧可以处理这条路线吗?我正在使用 .NET Core 3.0。
更新注意: 我已激活日志记录,并且看到 asp.net core 正在分析路由,我收到消息:没有找到记录器 Microsoft.AspNetCore 的请求路径“//ohif/study/1.1/series”的候选者。路由.EndpointRoutingMiddleware
处理双斜杠的中间件怎么样?
app.Use((context, next) =>
{
if (context.Request.Path.Value.StartsWith("//"))
{
context.Request.Path = new PathString(context.Request.Path.Value.Replace("//", "/"));
}
return next();
});
Run Code Online (Sandbox Code Playgroud)
在Web服务器级别重写URL,例如对于IIS,您可以使用URL重写模块自动重定向//ohif/study/1.1/series
到/ohif/study/1.1/series
. 这不适合您的申请。
归档时间: |
|
查看次数: |
5153 次 |
最近记录: |