Skip to content

IISRewrite Middleware appendQueryString #21464

@brianchance

Description

@brianchance

Describe the bug

When using the IISRewriteModule, redirects with appendQueryString="true" only work if there is a ? in the redirect url.

To Reproduce

Would expect this do work...

    <rule name="some rule" stopProcessing="true">
      <match url="^resource" />
      <action type="Redirect" url="/product" redirectType="Temporary" appendQueryString="true" />
    </rule>

To get this to work, you must append a ? to the action url...

    <rule name="some rule" stopProcessing="true">
      <match url="^resource" />
      <action type="Redirect" url="/product?" redirectType="Temporary" appendQueryString="true" />
    </rule>

Analysis based on source

In RedirectAction (/Middleware/Rewrite/src/UrlActions/RedirectAction.cs)
If the url contains a ? (line 72), the request query string is appended to the query string of the url.
The else only adds the request query string if QueryStringDelete != true

The UrlRewriteFileParser (/Middleware/Rewrite/src/IISUrlRewrite/UrlRewriteFileParser.cs) uses the the second constructor (line 222) of RedirectAction which defaults queryStringDelete: true (line 39).

Further technical details

  • ASP.NET Core version - 3.1.3
  • Include the output of dotnet --info
  • The IDE (VS / VS Code/ VS4Mac) you're running on, and it's version - VS2019 - Version 16.5.4

Metadata

Metadata

Assignees

Labels

area-middlewareIncludes: URL rewrite, redirect, response cache/compression, session, and other general middlewaresbugThis issue describes a behavior which is not expected - a bug.good first issueGood for newcomers.help wantedUp for grabs. We would accept a PR to help resolve this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions