Skip to main content


Showing posts with the label Razor Pages

Part - 7 | Asp.Net Core Identity Series[.NET 7] | Twitter Authentication

The main objectives of this article are: Implementing Twitter Authentication. Install Twitter Authentication NuGet Package: Let's install the required package for Twitter authentication. Visual Studio 2022: Install-Package Microsoft.AspNetCore.Authentication.Twitter -Version 7.0.4 Visual Studio Code: dotnet add package Microsoft.AspNetCore.Authentication.Twitter --version 7.0.4 Register Our App With Twitter: To enable Twitter authentication to our application we have to register our API with Twitter. So following are steps to register with Twitter. (Step 1) Register with 'Twitter Developers' section and then navigate to the dashboard page '' (Step 2) Click on 'Create Poject' on the dashboard page. (Step 3) Specify the project name and then click on the 'Next' button. (Step 4) Select a use case and then click on the 'Next' button (Step 5) Provide some project description and then click o

Part-3 | Asp.Net Core Identity Series[.NET 7] | Sending Two-Factor Authentication(2FA) Code To Email

The main objectives of this article are: Sending Two-Factor Authentication(2FA) Code To Email Enable Email 2FA: In Asp.Net Core Identity application to enable email Two-Factor Authentication, make sure our 'AspNetUser' table following fields has appropriate data: Email - Should not be empty or null EmailConfrimed - must be true TwoFactorEnabled - must be true. Now if we try to login into our application we can see a page to enter the 2FA code like below Send Two-Factor Authentication(2FA) Code To Email: Now let's update the code in 'OnGetAsync()' method in 'Areas/Identity/Pages/Account/LoginWith2faModel.cshtml.cs' as below. Areas/Identity/Pages/Account/LoginWith2faModel.cshtml.cs: public async Task<IActionResult> OnGetAsync(bool rememberMe, string returnUrl = null) { // Ensure the user has gone through the username & password screen first var user = await _signInManager.GetTwoFactorAuthenticationUserAsync(); if (user == null) { throw ne

Part-2 | Asp.Net Core Identity Series[.NET 7] | Registration Email Confirmation

The main objectives of this article are: Use SendGrid Email Service. Implement Email Confirmation For User Registration Send Grid: SendGrid is a third-party email provider from which we deal with 'send' and 'receive' operations of email to our application. SendGrid SMTP(Simple Mail Transfer Protocol) provider for email transfer. SendGrid also provides SendGrid .Net NuGet package that provides easy configuration to any .NET application. So to use the SendGrid SMTP we need 'Auth Key', 'From Email'. So let's register into SendGrid. The following are the steps to register and generate the API key in SendGrid: (Step 1) Go to SendGrid's official website at ''. Next do SingUp. (Step 2) Now login in to the SendGrid website, then under the left-hand side menu go to the 'Settings' ==> 'Sender Authentication'. At 'Single Sender Verification' click on the 'Get Started' button. (Step 3) Let'

Part -1 | Asp.Net Core Identity Series[.NET 7] Introduction & Project Setup

The main objectives of the article are: Introduction On Asp.NET Core Identity Create Razor Page Application(.NET 7) With Asp.Net Core Identity Generate Asp.Net Core Identity Tables Default Registration & Login Asp.Net Core Identity: Asp.Net Core Identity is a built-in login functionality library that supports authentication of all different .NET applications like "MVC", "Razor Pages", "And Blazor Server". Provides rich authentication UI pages which are customizable as well. Adoptable for external authentication providers like 'Google', 'Facebook', 'Outlook', etc. Can be integrated with other authentication like 'IdentityServer4', 'Azure Active Directory', 'Azure Active Directory B2C(Azure AD B2C)'. Create A .NET7 Razor Page Application With Individual Authentication: Let's create .NET7 Razor Page application with individual authentication to accomplish our demo. We can use either Visual Studio 202

.NET7 | Razor Pages | EF Core | One To Many Relationships | CRUD Example

In this article, we will implement Razor Pages CRUD operation with one-to-many relationships between the tables using the Entity Framework Core. Razor Pages: Razor Pages is a simplified web application model. Compared with the 'MVC' template, razor pages won't have 'Controllers', which means Razor Page is a combination of  'View' and 'Model'. The route will be configured within the razor page or view. A Razor Page composed with 2 files like '*.cshtml.cs'(Model) & '*.cshtml'(view). One-To-Many Relationship Table SQL Script: For this demo, we will create 2 tables 'Employee'(parent table) and 'EmployeeAddresses'(child table). Between the tables, we make a one-to-many relationship which means one employee record can have multiple records in the employee address table. Employee Table Script: CREATE TABLE Employee( Id int IDENTITY (1,1) NOT NULL, FirstName varchar (200) , LastName varchar (200) , JobRole varchar(50) CON