Posts

Showing posts with the label MVC

Localization in ASP.NET Core MVC with Example

Image
Using Query Strings for Request Culture and Simplifying Localization with IStringLocalizer Interface Let’s see how to implement Localization in ASP.NET Core MVC. In the first example, I am going to use the IStringLocalizer Interface in the controller to implement Localization. Additionally, when the user passes the desired language through the query string, it will display content in that language. First, let’s configure the settings in the program.cs file. builder.Services.AddLocalization(options => options.ResourcesPath = "Resources");  The AddLocalization method adds the localization service to the service container. I have added the supported cultures here. I have added two cultures: en for English and nl for Dutch. In the RequestCultureProviders , I have included QueryStringRequestCultureProvider() . This allows the system to determine the culture information from the query string. UseRequestLocalization initializes a RequestLocalizationOptions o...

A Step-by-Step Guide to Implementing Identity in ASP.NET Core MVC

Image
Are you ready to enhance your ASP.NET Core MVC project with the power of Identity? In this comprehensive guide, we'll walk you through the process of setting up and customizing the Identity system in your web application. By the end of this tutorial, you'll be able to implement secure user authentication and authorization for your ASP.NET Core project. Step 1: Create a New ASP.NET Core Web App Begin by opening Visual Studio and selecting "ASP.NET Core Web App (Model-View-Controller)" as your project template. Follow these steps: 1. Open Visual Studio and create a new project, selecting "ASP.NET Core Web App (Model-View-Controller)". 2. In the "Configure your project" window, enter the project name and choose the project's location. 3. In the "Additional Information" window, select the framework and choose "Individual Accounts" as the Authentication type. 4. Click "Create" to generate your project....

Azure Blob Storage With ASP.NET Core

Image
This blog will show you how to create a container and files in Azure Blob Storage. You must first install the Azure.Storage.Blobs package. Install-Package Azure.Storage.Blobs Create a container in Azure Blob Storage Let's start by learning how to create a container in Azure Blob Storage. A connection string is required for this. Go to Azure Blob Storage -> Access keys for that. There are two key values there. Choose the first option. The connection string will be concealed. When you click the show button on the right side, the connection string will be revealed. You can now copy the connection string. A code snippet for creating a container in Azure Storage is provided below. The connection string has been set up here. The instance of BlobContainerClient has been created. Using the BlobContainerClient instance, determine whether the container name exists or not, and if not, create a new container with the given name. The container name must adhere to the followi...

Read Values from appsettings.json in ASP.NET Core

Image
The appsettings.json file in ASP.NET Core contains all application settings. This blog will show you how to get the values from appsettings.json The following is an example of appsettings.json configuration. I have added a Sample setting here. It has two settings: AppName and Auth.The Auth setting contains Username and Password. appsettings.json "AllowedHosts" :  "*" , "Sample" : {    "AppName" :  "SampleApp" ,    "Auth" : {      "Username" :  "Parker" ,      "Password" :  "$@M9l3"   } } There are several methods for obtaining appsettings values. Let's go through them one by one. Method 1: Here the IConfiguration is injected to the HomeController constructor. Then using the GetValue<T> method the setting values are collected. The values are retrieved using the key. HomeController.cs public ...