Table of contents
Blazor
Blazor🡕 is a open-source SPA web framework developed by Microsoft that helps developers to build web apps using C# instead of JavaScript. Blazor is a feature from existing ASP.NET framework and this enables possibility for .NET C# developer to build Modern webapps by using C#, HTML, and CSS. Both client and server code is written in C#, allowing you to share code and libraries.
Blazor app hosting option
-
Blazor Web Assembly executes on the client-side within the browser. This implies that the complete application is downloaded to the web browser and executed there. As a result, the initial loading time is relatively long, but subsequent server loads are greatly reduced. It can function as a Progressive Web App, enabling users to install the app on their device and use it without requiring network access..
-
Blazor server-side where pre-renders HTML content before it is sent to the client’s browser which is similar to ASP.NET web forms architecture.
SQLite
SQLite🡕 is a server-less database and is self-contained. This is also referred to as an embedded database which means the DB engine runs as a part of the app. This is a great tool to set up quick development POCs within no time that requires database interaction. Very handy especially when we don’t have SQL server handy. You could also install SQLite extension for Visual Studio.
Steps
- In Visual Studio, create a new Blazor Server App, choose Individual Accounts for ASP.NET Identity
- Install nuget package
Microsoft.EntityFrameworkCore.Sqlite
- Modify
appsettings.json
file to includeSqliteConnection
connection(create the database file on the project root) as follows"ConnectionStrings": { "SqliteConnection": "Data Source=SqliteDB" },
- goto
Program.cs
& change the connection settings to use SQLite connection as follows
// Add services to the container. var connectionString = builder.Configuration.GetConnectionString("SqliteConnection"); builder.Services.AddDbContext<ApplicationDbContext>(options => options.UseSqlite(connectionString));
- goto
- By Default, the Data Migration scripts are on SQL server & SQLite scripts doesn’t support
NVARCHAR(MAX)
& hence replace them withmaxLength: 256
- Goto Package Manager Console & run
Update-Database
to create database on SQLite. - run the application & try to register a user
Repo
Please feel free to refer the github repository🡕
Summary
In this proof-of-concept (POC), we have learned the process of setting up a Blazor server application and configuring a SQLite database to be used for individual user Microsoft Identity. The User Identity feature can be extended and customized according to specific requirements, and I plan to document these details in separate upcoming blog posts.
Good luck, and keep Learning!!