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 (ie the contents of the /wwwroot folder) are not being served, eg
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?
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, eg "C:\\MyService"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.