Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deploy Blazor web application on file share

Tags:

blazor

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?

like image 856
David Avatar asked Nov 08 '22 00:11

David


1 Answers

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 at https://www.contoso.com/CoolBlazorApp and has a virtual base path of /CoolBlazorApp/.

like image 96
dani herrera Avatar answered Nov 29 '22 21:11

dani herrera