I am having troubles hosting the blazor wasm asp.net core hosted
application.. The solution has 3 projects: Client, Shared, and Server.
when I run the command dotnet publish --configuration Release
it publishes the libraries to their respective folders in solution like this:
- WebWorkbench3\Client\bin\Release\net5.0\publish
- WebWorkbench3\Server\bin\Release\net5.0\publish
- ...
I would assume that since the server
project is referencing a client
- then my steps to host the application are following:
- Open
WebWorkbench3\Server\bin\Release\net5.0\publish
in powershell - Run command
dotnet .\WebWorkbench3.Server.dll
- Navigate to:
https://localhost:5001/
- Result:
- Expected: client page opened
- Actual: page is stuck at "Loading.." string. In the console we see that there was an error about
_framework/blazor.webassembly.js
not being loaded.
- If we were to check the
wwwroot
folder contents in the server app we will see the following:
So this explains why the error is shown. However my question at this point - should the publishing process/configuration in project take care of copying client's wwwroot
contents into the the server's app output directory? If we start a debugging session in the VisualStudio, then we use the server
as the startup point, so the project should have some idea where to look up the blazor.webassembly.js
file at..
So why doesn't the same process occurs during the publishing?
Note: I was able to fix the issue by manually copying the client's wwwroot
directory and by placing the contents into the server's wwwroot
directory... But I don't think that is is how serving is supposed to work?
EDIT: I have just tried to set-up the client
blazor application in IIS. And it works. Kind of. The page is opened. But then when it tries to make a REST GET request to the server - it uses the same hostname:port
combination. So if my app is hosted on mysite.local:50001
then the request to API will look like mysite.local:50001/data/loadall
where data
is the controller name and loadall
is the action name.. So basically the client uses the same base address as the server.. The problem, is that I cannot start the server on the same port as the client! In attempt in doing so - you will see following output:
So basically I have the same question as before - how to host the wasm application that is split between client and the server? I am pretty sure that I can make it work by forcing the client to use the non-standard server port and serving the server
part on that port.. However, I believe there should be a reason why current configuration (default configuration in the blazor wasm template) is configured in this way so it should be possible to run the project somehow without any additional changes at all..