.net核心,如何使用多余的斜杠处理路由 [英] .net core , how to handle route with extra leading slash

查看:332
本文介绍了.net核心,如何使用多余的斜杠处理路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要处理以下形式的传入请求: //ohif/study/1.1/series 注意前面的斜杠

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

我的控制器签名是:

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

如果我将传入请求修改为/ohif/study/1.1/series,则效果很好

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

但是当我使用//ohif/study/1.1/series时,路线没有被击中

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

此外,我还尝试了:[Route("/ohif/study/{studyUid}/series")] 和[Route("//ohif/study/{studyUid}/series")]

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

均失败.不幸的是,我无法更改传入请求,因为它是来自外部应用程序的.有一些技巧可以处理这条路线吗?我正在.NET Core 3.0中工作.

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.

更新注意: 我已激活日志记录,并且看到asp.net核心正在分析路由,我收到消息: 找不到请求路径"//ohif/study/1.1/series"的候选对象 记录器Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware

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

推荐答案

在Web服务器级别重写网址,例如对于IIS,可以使用URL重写模块自动将//ohif/study/1.1/series重定向到/ohif/study/1.1/series.这不是您的应用程序的工作.

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.

这篇关于.net核心,如何使用多余的斜杠处理路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆