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

后端 未结 2 899
天命终不由人
天命终不由人 2021-01-16 06:46

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:

[Rout         


        
相关标签:
2条回答
  • 2021-01-16 07:03

    What about the middleware to handle double slash?

    app.Use((context, next) =>
                {
                    if (context.Request.Path.Value.StartsWith("//"))
                    {
                        context.Request.Path = new PathString(context.Request.Path.Value.Replace("//", "/"));
                    }
                    return next();
                });
    
    0 讨论(0)
  • 2021-01-16 07:07

    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.

    0 讨论(0)
提交回复
热议问题