问题
I created a new ASP.NET Core 3.0 Web application and selected the Model-View-Controller option. I wanted to add Blazor Server side, so I added the below to the Startup.cs file.
services.AddServerSideBlazor();
endpoints.MapBlazorHub();
and added the script file
<script src="_framework/blazor.server.js"></script>
in my Layout file.
I created a simple component that displays what I enter in a textbox, and added the component to my Index.cshtml
view. It works within Visual Studio, but when I push it up to my internal 2016 server, the component is rendered but the text is not displayed. The app can't seem to find the blazor.server.js
file.
Is there some other deployment step I am missing to push up the JS file?
回答1:
Finally figured it out, I had to add <base href="~/" />
in the head section of the "_Layout.cshtml".
Found the answer here.
回答2:
As blazor.server.js
is a static file, be sure to add app.UseStaticFiles();
in startup.cs
.
回答3:
In my case,
app.UseStaticFiles(new StaticFileOptions
{
ServeUnknownFileTypes = true,
DefaultContentType = "application/octet-stream"
});
is what caused the issue. Replace it with:
app.UseStaticFiles();
solved the problem. I figured maybe DefaultContentType
is where the problem is.
Anyone knows better why that is the case please update this answer.
来源:https://stackoverflow.com/questions/58088302/blazor-server-js-file-not-found