Posts

Showing posts from March 30, 2025

Single Sign-On (SSO) in .NET Core and Angular

Implementing Single Sign-On (SSO) in .NET Core and Angular Single Sign-On (SSO) is an authentication mechanism that allows users to log in once and gain access to multiple applications without needing to re-enter credentials. It enhances user experience and security by centralizing authentication. In this article, we will implement SSO using  OAuth 2.0 and OpenID Connect (OIDC)  with  IdentityServer4  in .NET Core and Angular.   Step 1: Setting Up IdentityServer4 in .NET Core IdentityServer4  is an open-source framework that enables authentication and authorization using OpenID Connect and OAuth2. 1.1 Create a New .NET Core Identity Server Run the following command to create a new Web API project: dotnet new webapi -n IdentityServer cd IdentityServer dotnet add package IdentityServer4 1.2 Configure IdentityServer in  Program.cs Modify  Program.cs  to add IdentityServer with clients, resources, and users. using IdentityServ...

Advanced Dapper Techniques: Stored Procedures, Transactions, and Bulk Operations

Advanced Dapper Techniques: Stored Procedures, Transactions, and Bulk Operations Using Stored Procedures Dapper allows calling stored procedures efficiently: var products = await db.QueryAsync<Product>("GetAllProducts", commandType: CommandType.StoredProcedure);   Handling Transactions To ensure  atomic operations , use transactions: using var transaction = db.BeginTransaction(); try {     string insertQuery = "INSERT INTO Products (Name, Price) VALUES (@Name, @Price)";     await db.ExecuteAsync(insertQuery, newProduct, transaction);     transaction.Commit(); } catch {     transaction.Rollback();     throw; }   Bulk Operations For  bulk inserts , use ExecuteAsync with multiple parameters: var products = new List<Product> { new Product { Name = "Item1", Price = 10 }, new Product { Name = "Item2", Price = ...

Getting Started with Dapper in .NET Core

  Getting Started with Dapper in .NET Core  Dapper is a lightweight and high-performance micro-ORM (Object Relational Mapper) for .NET that enables efficient database interactions. It's ideal for applications prioritizing speed and minimal overhead, offering a streamlined alternative to Entity Framework. This guide provides an enhanced approach to integrating Dapper into your .NET Core projects.   1. Installing Dapper Install the Dapper NuGet package using the following command: dotnet add package Dapper Alternatively, you can install it via the NuGet Package Manager in Visual Studio.   2. Setting Up Database Connection We'll use SQL Server for this example. Configure Connection String Add your database connection string to  appsettings.json: "ConnectionStrings": {   "DefaultConnection": "Server=YOUR_SERVER;Database=YOUR_DB;User Id=YOUR_USER;Password=YOUR_PASSWORD;" }     Inject Database Connection in  Program....