Description
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
After some research and testing to find a way to globally prefix my API routes with /api
, I have arrived at the following code:
var apiUrl = app.Configuration["RemotePath:Api"]!;
app.UsePathBase(!string.IsNullOrWhiteSpace(apiUrl) ? apiUrl : null);
app.UseRouting();
This works great, and now a endpoint method mapped to /foo/bar
is actually mapped to /api/foo/bar
. However...it seems there still exists a mapping for /foo/bar
.
Take this example controller in a project I'm working on:
[Route("upload")]
public sealed class UploadController : Controller
{
[HttpPut("oid/{oid}")]
public async Task<IActionResult> UploadOid(string oid, [FromBody] LocalFileBlobAdapter.RemoteFileLocation location)
{
...
return NoContent();
}
}
In Postman, I am able to make a PUT request to /api/upload/oid/{oid}
, and /upload/oid/{oid}
.
Expected Behavior
Using UsePathBase()
should not preserve the original controller routing configuration (IE, what the routing would be if UsePathBase()
had never been called).
Steps To Reproduce
app.UsePathBase("/api");
app.UseRouting();
Then add any applicable controllers. (I am using a Web API template project, so I'm unsure what other code is specific to my project and not just the defaults).
If needed I can create a brand new project and put it on GitHub.
Exceptions (if any)
N/A
.NET Version
7.0.102
Anything else?
JetBrains Rider, project is targeting net7.0
. Referenced packages, if of any use:
<ItemGroup>
<PackageReference Include="Estranged.Lfs.Api" Version="3.1.0" />
<PackageReference Include="Estranged.Lfs.Authenticator.GitHub" Version="3.1.0" />
<PackageReference Include="JWT" Version="10.0.2" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.2" />
<PackageReference Include="Octokit.Webhooks.AspNetCore" Version="1.4.0" />
<PackageReference Include="StackExchange.Redis" Version="2.6.104" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
</ItemGroup>