Rewrite rule do not work for long URLs in IIS

Zimon, Robert 0 Reputation points
2024-09-15T16:22:02.3733333+00:00

I am using IIS as reverse proxy that redirects traffic made to some domain name like domain.com to internal kestrel service at localhost:5000. I am using regular expression (.*) and I am redirecting that to localhost:5000/{R:1}. This works perfectly fine, but not for one case of the application.

There is one case when very long url is created (855 characters) and then I am receiving bellow response:

User's image

The same url copy pasted to localhost:5000 works fine.

I realized that when I remove (approximately) half/ more than half of the url I am receiving another response:

User's image

When I check service logs I see that first request do not went through to the application while second was logged, so I assume that request with full url was not redirected at all.

When I click test rule in IIS I see that this window is also cutting the url

User's image

Are my assumptions correct? Is there any way to make it works?

Internet Information Services
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Lex Li (Microsoft) 5,582 Reputation points Microsoft Employee
    2024-09-15T21:40:13.8266667+00:00

    HTTP requests are initially processed by http.sys and can be rejected at this stage before reaching the IIS pipelines.

    This explains why you saw that 400 error page, even if you configured rewrite rules and the execution of URL rewrite rules is at the start of the pipelines.


  2. Jinlei Shuang-MSFT 80 Reputation points Microsoft Vendor
    2024-09-16T05:52:38.9933333+00:00

    @Zimon, Robert

    HTTP Error 400 happens when a server cannot understand a request that's been made of it. In your situation, the reason of Bad request error is invalid URL. You can try to Increase Query String and URL Length Limit in IIS.

    1. Open the site in IIS and double click the Request Filtering module. User's image
    2. Click the Query Strings, then right click in the white area shown below then click the context menu option called Edit Feature Setting.

    User's image

    1. change the value of Maximum URL length and Maximum query string to something more appropriate for your needs.

    User's image

    You can refer to here and here to know about the Element for request limits.

    Best regards,

    Jinlei Shuang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.