Dotnet core + (plus) sign in Web API routing

主宰稳场 提交于 2019-12-23 08:59:53

问题


I work on web API project in the dotnet core and check user mobile number exists check.

[Route("api/[controller]")]
public class UserController : Controller
{
    [HttpGet]
    [Route("mobile/exist/{mobile}/{id:int?}")]
    public async Task<IActionResult> MobileExist(string mobile, int? id)
    {
        return Json(await _userService.MobileExist(mobile, id));
    }
}

Request URL:

http://localhost:3364/api/user/mobile/exist/+123456

When I request above URL with the plus sign it given an error.

The Same URL without + sign it's working good.

I try with encoded + sign with %2B but it not working

How can I request with plus sign?


回答1:


This is an IIS issue:

Please look at the following post:

double escape sequence inside a url : The request filtering module is configured to deny a request that contains a double escape sequence

If you try to run your app with Kestrel, you will see that it works. For IIS, you will need to add the following section in you web.config:

<system.webServer>
  <security>
    <requestFiltering allowDoubleEscaping="true" />
  </security>
</system.webServer>


来源:https://stackoverflow.com/questions/43801559/dotnet-core-plus-sign-in-web-api-routing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!