Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A way to change IFileProvider that FileVersionProvider (asp-append-version) is using? #17409

Closed
datvm opened this issue Nov 26, 2019 · 1 comment
Labels
area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates question

Comments

@datvm
Copy link

datvm commented Nov 26, 2019

Is your feature request related to a problem? Please describe.

I want to be able to serve files with a custom file path (js/v1/foo.js can be mapped to a real file at wwwroot/js/foo.js). I created VersionedFileProvider which could map that already. I set it like this:

    app.UseStaticFiles(new StaticFileOptions()
    {
        FileProvider = new CompositeFileProvider(
            new VersionedFileProvider(env.WebRootPath),
            env.WebRootFileProvider),
    });

All files are working. However, if I use that custom path, asp-append-version does not work. When I check the source code, they are taking WebRootFileProvider instead of the one I am setting in UseStaticFiles.

Luckily, env.WebRootFileProvider is settable, so I can resolve the problem with:

    env.WebRootFileProvider = new CompositeFileProvider(
        new VersionedFileProvider(env.WebRootPath),
        env.WebRootFileProvider);
    app.UseStaticFiles();

For now I have not seen any problem yet. However, I have to admit I do not know what else is using WebRootFileProvider and what side-effect can possibly happen. Please help me confirm this is a proper way to resolve my issue.

Describe the solution you'd like

Can we have a way to set IFileProvider that FileVersionProvider is using? Or at least a documentation text that confirms setting env.WebRootFileProvider is okay? Thank you.

@datvm datvm changed the title A way to change IFileProvider that FileVersionProvider is using? A way to change IFileProvider that FileVersionProvider (asp-append-version) is using? Nov 26, 2019
@javiercn javiercn added the area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates label Nov 26, 2019
@mkArtakMSFT
Copy link
Member

Thanks for contacting us. The way you've configured it is what we would also recommend.

@ghost ghost locked as resolved and limited conversation to collaborators Dec 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates question
Projects
None yet
Development

No branches or pull requests

3 participants