Skip to main content


Showing posts with the label .Net5

AutoMapper In Asp.Net Core Applications

AutoMapper: Automapper is an object-to-object mapper. Object to object mapping works by transforming an input object of one type into an output object of a different type. Manually mapping one object property value to another object property value leads to more lines of code, so all this dirty work can be avoided by using the Automapper. As long as all properties names are the same for 2 different objects that need to map, almost zero configuration is needed to map them.  When To Use AutoMapper?: In any kind of architecture, it is always advised to not expose the 'Entity'(Table classes) directly. So we will create replica classes for 'Entity' we called them as 'DTO'(Data Transfer Object) or 'VM'(View Models). So this is the real-time best case to use Automapper for mapping 'Entity'(Table classes) data to DTO or VM's. Create A Sample Dotnet5 Web API Project: In this demo, we are going to understand the different mapping techniques that are

An Overview On SameSite Cookie Options In Dotnet Core Application

The SameSite cookie option is used by the browsers to determine whether to attach or remove the cookie for a request. So to understand all the options of SameSite cookie, here we are going to check different scenarios with the help of 2 different domains like "" and '' . The  "" is a dotnet5 MVC application where have login cookie authentication enabled, so here we will check the SameSite option for my login cookie(SameSite option applied to any kind of cookie, here I'm just using the login cookie for my testing). So here I enable the 'Authorization' attribute on my index page, so only authenticated users can access it. The  '' is a normal dotnet5 MVC application where we consume the  "" website as a link or iframe. AspNet Core Cookie SameSite Options: The following are the cookie SameSite options: Strict Lax Non

IdentityServer4 Protecting Web API Using Client Credentials - Implement IClientStore And IResourceStore

In this article, we will implement an IdentityServer4 to protect a Web API with client credentials. Client Credentials Flow: Client credential flow suitable internal communication between that application. In this flow application request the IdentityServer jwt access token to consume the protected API resources. Client Credential flow requires 'ClientId', 'ClientSecret' for authentication. Clients are applications that want to consume the protected API by the IdentiyServer. Each client should register with IdentiyServer. So IdentityServer stores client information like 'ClientId'(unique identifier), 'ClientSecrets', 'Scopes' etc. So clients using 'ClientId', 'ClientSecret', 'Scopes'(optional) can request the IdentityServer as a trust client to get the JWT token. Protected API's are registered under IdentityServer as 'ApiResoucers' with set of 'Scopes'. So any client to access the protected API, then cl

Introduction On OData(Version 8) In .Net5 Web API Application

In this article, we are going to understand the steps to integrate OData(Version 8.0) into our .Net5 application. OData: The OData(Open Data Protocol) is an application-level protocol for interacting with data via a RESTful interface. OData supports the description of data models, editing, and querying of data according to those models. OData's main advantage is users can query the API results. So OData query or filter can be done in two different approaches: Approach - 1: A response collection from an action method can be filtered by the OData. Means if action method fetched the collection of records from the database and returning to user, in the middle OData will filter the response data based on user query. Approach - 2: Action method that returns an entity framework query of type 'IQueryable', then OData generates a SQL query based on the user OData query request, then executes against the database and then returns the result to the users. OData query features are: $se