N
N
NakedSnake272021-09-18 13:43:37
ASP.NET
NakedSnake27, 2021-09-18 13:43:37

What is the correct way to use the DefaultFilesOptions property inside the UseFileServer method?

Hello, this is a newbie question. I found the answer in Google, Stack and Habré, so I'm writing here (and if there is, then don't blame me).
I am studying ASP.NET Core and learned about the UseFileServer method, which combines three methods for working with static files. And I have a question: how to make the default file in it. Without it, it is done like this:

DefaultFilesOptions options = new DefaultFilesOptions();
            options.DefaultFileNames.Clear();
            options.DefaultFileNames.Add("start.html"); 
            app.UseDefaultFiles(options); 

app.UseStaticFiles();

And when I try to render using FileServer:
app.UseFileServer(new FileServerOptions
            {
                DefaultFilesOptions = { DefaultFileNames = new[] {"start.html"}},
            });

Then nothing comes out and the default hello world is shown.
Please suggest a solution to this problem.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question