Reputation: 1118
I have an incomprehensible bug recently.
I published a ASP.NET Core MVC web application to a folder, when I enter the root path of the website and run it using command
d:\publish> dotnet WebSite.dll
all things works fine.
but when I go to the parent folder of this website, and then use below command to run it.
d:\> dotnet ./publish/WebSite.dll
the web site can visit,but all the static files given a 404 error,
I want to know, why? how can I solve this?
Upvotes: 3
Views: 2829
Reputation: 1118
Because UseStaticFiles
use the path from env.ContentRootPath
, But env.ContentRootPath
will take path where you run the dotnet
command, so the physical path is getting wrong.
I have reassign the base physical path like this:
app.UseStaticFiles(new StaticFileOptions()
{
FileProvider = new PhysicalFileProvider($@"{AppDomain.CurrentDomain.BaseDirectory}/wwwroot")
});
And all static resources are revisited.
Upvotes: 9