`UrlHelper.Content` overload that accepts an `appendVersion` argument
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 281
Description
### Is there an existing issue for this?
- [X] I have searched the existing issues
### Is your feature request related to a problem? Please describe the problem.
I am trying to declare an import map in my web application. So in `_Layout.cshtml` I will write something like:
```
{
"imports": {
"my-module": "@Url.Content("~/path/to/my/module.js")"
}
}
```
However, this does not get the benefits of `asp-append-version`, and the way to achieve the same result as `asp-append-version` is not obvious.
### Describe the solution you'd like
Currently, the `ImageTagHelper`, `LinkTagHelper`, and `ScriptTagHelper` all privately re-implement this same method:
https://github.com/dotnet/aspnetcore/blob/d05f3586adc0439595436ff6b8677548302fd64d/src/Mvc/Mvc.TagHelpers/src/ImageTagHelper.cs#L140-L158
https://github.com/dotnet/aspnetcore/blob/d05f3586adc0439595436ff6b8677548302fd64d/src/Mvc/Mvc.TagHelpers/src/LinkTagHelper.cs#L532-L551
https://github.com/dotnet/aspnetcore/blob/d05f3586adc0439595436ff6b8677548302fd64d/src/Mvc/Mvc.TagHelpers/src/ScriptTagHelper.cs#L412-L430
I think these should be deduplicated into a single implementation. Perhaps `UrlHelper` itself could contain this bit of logic and expose it via `UrlHelper.Content(contentPath, appendVersion)`, or perhaps it would be better encapsulated by some new service type which could then also be used by `UrlHelper.Content(contentPath, appendVersion)`.
Either way, I would really like to see `UrlHelper.Content(contentPath, appendVersion)`.
### Additional context
_No response_
Contributor guide
Research direction
Start by reading the existing private implementations in ImageTagHelper.cs, LinkTagHelper.cs, and ScriptTagHelper.cs at the linked locations, then inspect UrlHelper.Content and the surrounding MVC Tag Helpers code. Done means the repeated content-versioning logic has a shared implementation and UrlHelper.Content supports the requested appendVersion use case, with coverage for the new behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- backend, web-dev
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100