Blazor can be used to create a client-side-C#-scripted webpage. I have read in various places (like MSDN Magazine article) that once built I can put the files on any server. My understanding is that placing the artifacts on a file share should be possible, too.
Yet, this is not what I observe. Running dotnet run
in the project directory of the Blazor Web Application I created via the template in Visual Studio makes the kestrel webserver spin up and I can reach the working web page via the indicated http://localhost:port/
address.
When I open the index.html
which was generated under the WebApplication1\bin\Debug\netstandard2.0\publish\WebApplication1\dist
path with the help of dotnet publish
I only see a text saying "Loading..." in my web browser.
I have looked into the index.html
and at first sight it looks like the path to the _framework/blazor.webassembly.js
matches the directory structure. Where is the catch?
You say:
When I open the index.html which was generated under the WebApplication1\bin\Debug\netstandard2.0\publish\WebApplication1\dist path with the help of dotnet publish I only see a text saying "Loading..." in my web browser.
This is because Blazor expect to locate dll's on root path. I mean, all will work fine if you copy the content of dist
on the root of your web server but not if you copy it on a "subfolder" of root.
If you want to serve files from a path (instead from root), then you should to set app base path I mean, change:
<base href="/" />
to
<base href="/your_path/" />
on index.html
page.
From docs:
The app base path is the virtual app root path on the server. For example, an app that resides on the Contoso server in a virtual folder at
/CoolBlazorApp/
is reached athttps://www.contoso.com/CoolBlazorApp
and has a virtual base path of/CoolBlazorApp/
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With