Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dotnet core + (plus) sign in Web API routing

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?

like image 824
Sender Avatar asked May 05 '17 09:05

Sender


People also ask

How do I enable routing in .NET Core?

Inside the ConfigureRoute method, you can configure your routes; you can see that this method has to take a parameter of type IRouteBuilder. The goal of routing is to describe the rules that ASP.NET Core MVC will use to process an HTTP request and find a controller that can respond to that request.

Does .NET Web API provides routing support?

Web API 2 supports a new type of routing, called attribute routing. As the name implies, attribute routing uses attributes to define routes.

What is NET Core routing in Web API?

Routing in ASP.NET Core Web API application is the process of mapping the incoming HTTP Request (URL) to a particular resource i.e. controller action method. For the Routing Concept in ASP.NET Core Web API, we generally set some URLs for each resource.


1 Answers

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>
like image 182
Avi K. Avatar answered Oct 05 '22 23:10

Avi K.