nogood
nogood

Reputation: 1320

How to deploy Blazor untouched DemoApp BUT with working Authorization (BlazorServer)

I can't come up with a solution by myself ... for the following Task!

I try to deploy the untouched Blazor template from Visual Studio (Blazor Server (not WebAssembly) with Authentication ON (individual users).

If I start the app locally on my PC everything works fine. I can register a Account log in etc.

But If I "Publish" the Blazor App and upload it to my Hosting Side I cant use the Authentication Register/Login etc. (Hosting on interserver.net / ASP.NET Web Hosting (0 of 25 MSSQL used) / config with plesk)

I get a Server Status 500 Error.

Some points to mention. I set the App Template to work with "App will store User internal".

I am pretty much a noob to Databases, SQL etc..


My thoughts are that the problem is that I use the "App store User internal" Option right at the creation of the Project. True?

Do I need to also publish my SQLDatabase that is auto created with the Template (locally) to my server? (yes then -> how ?)

Do I use the DB Connection String from appsetting.json and create a DB on my Server with the same name as the local db? But at my hoster if I want to add a SQL db I have to create a User and a Password. At the local Project I didn't have to enter a User or a passwordd so how to do that then?

Extremely sorry for my lack of knowledge. Please share your knowledge to help me find some peace after all...

Upvotes: 1

Views: 765

Answers (1)

Quango
Quango

Reputation: 13468

When you create a Blazor application using Identity with local user accounts, it defaults to using Entity Framework and Microsoft SQL Server, specifically SQLexpress on your development machine. If you check Startup.cs you should see:

   services.AddDbContext<ApplicationDbContext>(options =>
       options.UseSqlServer(
           Configuration.GetConnectionString("DefaultConnection")));

As your hosting service is providing MySql, that's not going to work, so you need to replace this. It makes sense to remove SqlServer from your template and switch to using MySql on your development machine so the two use the same code.

When you run locally the connection string used comes from appsettings.json. When you publish, if there is a file called appsettings.Production.json any settings in here will be used instead, so you can put the connection string to connect to the hosted MySQL database in there.

I'm not an expert on setting up MySQL so I'd suggest you look at ".NET Core 3 — Blazor App and Security with Identity and MySql" which should help in the process.

Upvotes: 1

Related Questions