dotnet / dotnet/aspnetcore

Rewrite module - Rule action not working with rewrite maps

Open
#24,618 7 comments 0 reactions 0 assignees View on GitHub
area-middleware bug feature-rewrite-middleware help wanted
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 10h
Merged PRs (30d)
281

Description

### Describe the bug
Using rewrite maps in the URL attribute of a rewrite rule action doesn't seem to work.
If we have the following rules and rewrite maps defined:

```xml
























```

The first rule works correctly and performs the redirect from `somepage.html` to `otherpage.html`.
However, the second rules doesn't seem to work and a request to `index.html?id=1234-1234` doesn't redirect to the expected `index.html?id=ABCD-ABVD`.

Also, if the URL value of the second rule is changed to something "hardcoded" such as "bing.com", then the redirect action is performed which indicates the issue seems not to be related to the condition pattern but to the action URL.

### To Reproduce

- Create a .net core web application (empty template)
- Add the Microsoft.NetCore.Rewrite package
- Create the rewrite file using the rules above
- Configure startup.cs to load the iis rewrite file
- Run the application and try with the requests mentioned on the description above

[Link to the project in GitHub](https://github.com/nuno-barreiro/aspnetcore-issue-urlrewritemaps)

### Exceptions (if any)

N/A

### Further technical details
- ASP.NET Core version 2.1 (but it happens with 3.1 too)
- Visual Studio Enterprise 2019

▶ dotnet --info
.NET SDK (reflecting any global.json):
Version: 5.0.100-preview.4.20258.7
Commit: 65f0fc2cad

Runtime Environment:
OS Name: Windows
OS Version: 10.0.19042
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\5.0.100-preview.4.20258.7\

Host (useful for support):
Version: 5.0.0-preview.4.20251.6
Commit: 47ec733ba7

.NET SDKs installed:
2.1.806 [C:\Program Files\dotnet\sdk]
3.1.300 [C:\Program Files\dotnet\sdk]
5.0.100-preview.4.20258.7 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
Microsoft.AspNetCore.All 2.1.18 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.20 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.18 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.20 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.0-preview.4.20257.10 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.18 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.20 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.0-preview.4.20251.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.1.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 5.0.0-preview.4.20251.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Contributor guide

Open the contributing guide

Research direction

Start by running the linked minimal repro with the Microsoft.NetCore.Rewrite package and the rules in its rewrite file, then read startup.cs to confirm how the IIS rewrite configuration is loaded. Compare the working condition URL with the action URL using rewrite maps; done means the second request redirects from index.html?id=1234-1234 to the expected mapped ID.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
backend, web-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.