Today I feel I need to comment on the struggle I’m having with getting my Blazor WebAssembly app to work on my Windows server.
I have set up a Blazor WebAssembly template with built-in accounts.
When I launch the project locally on IIS Express with Visual Studio in debug mode, everything works fine and as expected.
However, as soon as I publish the Blazor WASM on the web server in the live environment, the client side of the app loses the “connection/token/authentication”. I’m not sure about this and in 3 days I couldn’t figure out what exactly is wrong.
While you stay logged in on the server side of the Blazor Web Assembly app, you are redirected to the main page running on the client app, and there you always get this one error that says everything and nothing.
The server is a clean Windows Server 2016 installation. It is a simple test virtual machine from my server provider, with 4 GB RAM and 2 CPU. Enough to test and develop most things.
I received an SSL certificate from my server provider to enable https on the server and add an extra layer of security to the http protocol.
With the private and secret key, I was able to successfully add the certificate to the certificate folder.
After the certificate was successfully implemented, I configured the IIS web server and bound the certificate to the IIS web server as well.
I added Microsoft SQL Management Studio to the server to manage and configure the database and installed Microsoft SQL Server 2019 Developer Edition.
The SQL Server is delivered with default settings and nothing out of the ordinary has been changed.
I have created an SQL user and a Windows user and given them access to the database. This way, handling the database will no longer require the administrator account.
I added the Windows user to the security groups and gave both users permission to the database.
This is a setting you can make in the SQL Server settings and must be made if you want to authenticate with the SQL user, as the default is set to “Windows Authentication Mode”.
To be honest, this setting drove me crazy as I had forgotten it and could not log in with the SQL user.
Added Visual Studio to the server and created my first Blazor web assembly app. Super excited about the idea behind the structure and much nicer than the old MVC Razor stuff I was never a real fan of.
I have a real project for the app and it’s not just for testing purposes. I chose Blazor WebAssembly because I need an API and a web interface for my indie game company Stusse Games.
The entire solution so far is the standard Blazor WebAssembly template with built-in user accounts, Core Hosted.
I change the connection string and update the database
The migration of the standard AspNet identity database was successful and can now be used from the Blazor server side via the Entity Framework.
This will enable the registration and authorisation of users on the website, which is mandatory for the project.
So the project is set up, the database is injected and the connection string has the right information!
Let’s start the IIS Express and start a round of debugging to see what’s going on.
It hasn’t been hard to create a Blazor WebAssembly app so far. The basic template also provides a login, which I also tested.
I registered and logged in successfully.
So up to this point, everything has worked wonderfully and as expected.
Of course, there are many things to consider about the authentication system and securing the server.
But first, let’s create a simple Blazor WebAssembly app that gives us a login and authentication system. Then we can extend the app as needed and add more security.
I uploaded the Blazor WebAssembly app to the IIS ad server and to see the app in action in a live environment.
The upload worked fine, then I went to https://www.stusse-server.com. The website launched and everything seemed normal and working. I went to the “Login” tab, which redirects to the server page of the app and opens the possibility to login.
I have now logged in and then the redirection to the main website (client side) starts and there the error message “There was an error trying to log you in. ” begins.
Mhh there are a number of things going on and the troubleshooting options are very limited. Actually, I don’t know how to debug this live environment properly to get more accurate answers as to what went wrong and I’ d be grateful for information here already.
I have now spent a few days researching with a friend to solve this problem with authentication. Unfortunately without any effective result.
I have tried so many different tutorials that I have found on the World Wide Web. I have read so much in the Microsoft documentation. I have checked the settings over and over again, tried so many options and variations.
But no matter what I try, the client side of the Blazor WebAssembly always loses the “Login/Authentication/Token”, or whatever.
This error only occurs in the live IIS web server environment, not in localhost debug mode.
However, the user is still logged into the backend.
Not only did I test this from my end, but I also asked friends and other people to recreate the scenario with the same result.
For some reason, some people can’t even access the website.
Also, some people mention that they cannot access the website from their PC.
This is now on top of everything else, but could be interesting for the solution
The first conclusion I draw is that I really need help from someone who knows what is going on. For example, how the server setup needs to be or someone who can tell me more about authentication in both Blazor Server and Client App in a live environment.
So far all the tutorials and even the Microsoft documentation only work locally on my Windows Server in debug mode.
And no one shows or explains how to set it up for a live environment.
I am at the end of my ideas and need help to solve the problem. If you have any idea what my problem could be. Feel free to contact me at my social media accounts or email
I also posted in the Microsoft Q&A a Topic to this, so feel free to answer there.