Reputation: 4020
I have an ASP.NET Core v3.1 application hosted in a Windows Service. When I run the service locally, everything works as expected. However, when I publish it and deploy it out to a server the static files (i.e. the contents of the /wwwroot folder) are not being served, e.g
My service exists on my file system like so, and the wwwroot contains all the necessary files:
As per Microsoft documentation, I understand that the reason for this is because the working directory of the Windows service is the C:\Windows\system32 folder, which isn't a suitable place to drop the wwwroot files. How do I configure the location of the wwwroot folder?
Upvotes: 2
Views: 1060
Reputation: 4020
In the Startup.cs class Configure() function, I needed to add the following:
app.UseStaticFiles(new StaticFileOptions
{
FileProvider = new PhysicalFileProvider(
Path.Combine(workingDirectoryPath, "wwwroot"))
});
where 'workingDirectoryPath' was an absolute path to the directory where my service executable is, e.g. "C:\MyService"
Upvotes: 3