Skip to main content


Showing posts with the label core 3.0 Preview

Refresh Token For JWT(JSON Web Token) On Authenticating .Net Core Application

In  Part-1 .Net Core Authentication Using JWT(JSON Web Token) , we have discussed step by step implementation about generating authentication token using JWT(JSON Web Token). Now we will discuss the generation of refresh token and using refresh token we will fetch authentication token again on its expiration. This article will be the continuation of  Part - 1 . RandomNumberGenerator Instance: System.Security.Cryptography.RandomNumberGenerator will be used to generate a random number which will be used as a refresh token. Note: It is not a mandatory approach to use 'System.Security.Cryptography.RandomNumberGenerator'. You can use your own some secured technique to generate a unique token string or you can use GUID. Generate Refresh Token: Let's add a private method that returns a random unique key that we can use as a refresh token. Logic/AccountLogic.cs: private string GetRefreshToken() { var key = new Byte[32]; using (var refreshTokenGenerator = RandomNumberGenerator.C

Split HTML And C# Code In Blazor Using Either Partial Class Or ComponentBase Class

By default Blazor component file consists of HTML code and C# code under the single file. For better coding standards we can split HTML code and C# code to separate files using concepts like: Partial Class ComponentBase Class Create Sample Blazor Server Application: Blazor Single Page Application comes with two types of templates like  (1) Blazor Server,  (2) Blazor Web Assembly . Let's create a Blazor Server templated sample application to understand to split the *.razor(Blazor file extension) files.  Using Visual Studio 2019 using a rich user interface we can create Blazor Templated application very easily. But for this sample, I'm using .Net Core CLI(Command Line Interface) with Visual Studio Code IDE.   Click to know how to use Visual Studio Code Editor for .Net Core applications . .Net Core Blazor Server CLI Command:- dotnet new BlazorServer -n Your_Application_Name Blazor project preview:- Open a command prompt whose path needs to be pointed to the  Startup.cs file

.Net Core Session Management

The Session helps to store user data in the application memory. Since the user data stores on the application it quick and fast to access. .Net Core Session data stored application using the cache, this cache can be either In-Memory or Distributed Cache.  Session Work-flow: On the user request the application from the browser, the server will create a session with an id called Session-Id.  This Session-Id will be given to the user in response by storing it in the cookie. So on every next request, this cookie will reach to the application which contains Session-Id.  An application uses the SessionId as the main key and stores all user data in the application cache. So by receiving a cookie from a client with Session-Id application will fetch the session stored data as per request.  This cookie session is browser-specific it is not sharable between browsers.  We can set session time out in our application, where after the time session data will get automatically cleared. Create A Sample

Blazor: Blazor Client-Side CRUD Operations (Part 4)

Introduction: In  Part 3  we have discussed on Update Operation using Blazor client-side application. Now we get hands-on Delete Operation in our sample application. Delete Operation: For a delete operation, we use a bootstrap modal for confirmation. Opening and closing of bootstrap in this sample we are going to use bootstrap js. In Blazor not all the operations related to UI can't be done alone with c#, we need to use javascript in few areas. But invokation of the javascript method will be done from the c# method using JavaScript Interoperability. Step 1: Goto "wwwRoot" folder open index.html file add the bootstrap js  links  as shown  below <script src="" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script> <script src="

Blazor: Blazor Client-Side CRUD Operations (Part 3)

Introduction: In  Part 2  we created a page to fetch all the data in Blazor Client-Side application. Now we are going hands-on UPDATE Operation. Update Operation: Step 1: In the "Pages" folder create a new razor file name it as "EditPlayer.razor".This page is used to update or edit the data in our Balzor Client-Side application. Now to navigate to this new page we need to add Blazor routing with "@page" directives. Add the routing code as below. @page "/player/edit/{PlayerId:int}" "PlayerId:int" is a placeholder in the URL, where the application expects numeric value in that place from the incoming requests. If we try to pass any string value in place of numeric, the application throws an error as no end found with your request. "PlayerId" data get accessed in c# code by creating c# property with same name "PlayerId" and it should be decorated with attribute "[Parameter]" which can observe in

Blazor: Blazor Client-Side CRUD Operations (Part 2)

Introduction: In  Part 1  we have worked on the CREATE Operation page in blazor client-side application. Now here we going to discuss on the READ Operation in blazor client-side application. Read Operation: Step 1: In the "pages" folder, add a new file name as "ShowPlayers.razor". Add players route in the file using "@page" directive as below. @page "/players" Run command "dotnet watch run" and navigate to "http://localhost:5000/players". Step 2: Add the HTML to show all the cricket players that we had created in our application as below <div class="row"> @foreach (var player in players) { <div class="col-sm-4"> <div class="card"> <img src="/images/player.jpg" class="card-img-top"> <div class="card-body"> <h4 Card-title>@player.FirstName @player.LastN

Blazor: Blazor Client-Side CRUD Operations (Part 1)

Introduction: Blazor client-side framework is to build interactive client-side single page web apps which work in all modern web browsers, including mobile browser. The code is written in c# which can run on the browser like javascript frameworks (angular, react, vue etc). In Blazor client-side framework Dotnet Code executed via WebAssembly in the browser runs in the browser's javascript sandbox securely. Specs: 1. core 3.0 Preview 2. Blazor (Client-side) 3. Bootstrap 4 4. VisualStudio Code Editor Core Concept: Blazor client-side application sample CRUD (Create, Read, Update, Delete) operations. Let's create a sample application of the Indian cricket team players using the Blazor template. Our final sample looks as follows Create Operation: Step 1: Create Blazor client-side application.  Step by step process to create a blazor template . Step 2: Go to Pages Folder, add a new file name it as "AddPlayer.razor".Now add the follo