0

I have an action method that accepts a userid (Guid) and token (url encoded string) as a web api end point in a Asp.net Core 2.2 project as shown below:

[HttpGet]
[Route("{userId}/confirm/{token}")]
public async Task<IActionResult> GetConfirmationAsync([BindRequired, FromRoute] string userId, [BindRequired, FromRoute] string token)
{
        var result = await _userService.GetConfirmationAsync(userId, token);

        if (!result.Success) return StatusCode((int)result.HttpStatusCode, new ErrorDetailsResource(result.Messages.ToList(), result.Exception));

        return Ok();
}

When I submit a request with a short token string such as

http://localhost:44353/api/Account/d73d17fc-9f58-471a-9f21-312aede320fc/confirm/CfDJ8Jcfzk

The request goes through. However, when I submit a request such as the one below:

http://localhost:44353/api/Account/d73d17fc-9f58-471a-9f21-312aede320fc/confirm/CfDJ8JcfzkHibeBAsl9sKBtm51FA6t6I91nMeDwJjMNi0lkxw8OzLRIat7U9zx5feED0xz426GjJlzbr9e3AWfGBrZXhsstZvDTNBdbpMnr7diBSIMnWeBa3RE5Rqay2G%252fc3QxgizIcmOp%252fOtIFoca5X3kOMhV3dJ%252bYSwccpKLwosMNbHkcRQ9Hi3qWhtWBV4FRYT5tlqZyIWR863AeXE3fiNGdmvaCkZLReNxMCT8N8riT6bWhr7ZrboEmW3JIcrsvlvw%253d%253d

I am getting the following message when I run the app in IIS Express:

Bad Request - Invalid URL HTTP Error 400. The request URL is invalid.

I have tried the following configuration in Program.cs, but it does not work

WebHost.CreateDefaultBuilder(args)
   .UseConfiguration(configuration)  
   .ConfigureKestrel(options =>
   {
      options.Limits.MaxRequestBufferSize = 512000 * 1024; 
      options.Limits.MaxRequestLineSize = 512000 * 1024;                        
   })
   .UseStartup<Startup>()
   .Build();

Where can I configure to set the Max Request Url Length in Asp.net Core 2.2 so the request is valid?

Thanks for any help!!

Jenni
  • 85
  • 2
  • 5

1 Answers1

0

You are seeing the max segment length of 260 characters. Your encoded string has 284 characters. See Link for more details. There is a workaround where you can change an entry in your registry as discussed here Link

eVolve
  • 1,340
  • 1
  • 11
  • 30
  • 2
    What if you're on a web app like aws elastic beanstalk or azure web apps or running asp.net core on linux? Anything on the startup? – Dan Parker Feb 21 '20 at 20:54