Archives

Archives / 2019
  • Use Google Charts in AspNet Core

    At time your ASP.NET Core web applications want to display certain data in the form of bar chart or pie chart. Although there are plenty third-party components and libraries that you can use to accomplish this task, Google Charts is a simple yet feature rich client side option. To that end this article shows how Google Charts can be used to render simple bar charts and pie charts.

  • Use IHttpClientFactory to invoke Web API in ASP.NET Core

    If you have worked with ASP.NET Core Web APIs before, chances are you used HttpClient to invoke them. Although instantiating HttpClient directly is a common way of using it, there is a better alternative. Rather than instanting HttpClient yourself you can use IHttpClientFactory to obtain an instance of HttpClient. The HttpClient object thus obtained can be used to invoke the Web API. In this article I discuss three ways to obtain an HttpClient instance using IHttpClientFactory.

  • .NET Standard for Absolute Beginners

    If you are a beginner in ASP.NET Core chances are at some point in time you stumbled upon this - .NET Standard. You probably wondered what it is and how is it different than .NET Framework and .NET Core. Although you might have heard this term, while developing your ASP.NET Core apps you might not have bothered about it at all. This might have made you wonder even more as to what's the use of .NET Standard if it's not actively used while developing your apps. You might have also felt bit confusing about the version number that accompanies .NET Standard. This article attempts to explain all these questions about .NET Standard from beginner's perspective. My aim is to quickly enable you to grasp the concept and utility of .NET Standard and I also provide pointers for more detailed understanding.

  • CRUD using gRPC, EF Core, and ASPNET Core (Part - 3)

    In Part -1 and Part - 2 of this article you created EmployeeCRUD service definition using Protocol Buffer language and also implemented it in EmployeeCRUDService class. So, our gRPC service is now ready. In this part we will consume the service in an ASP.NET Core MVC application. Begin by opening the GrpcService1 project you created earlier. Add a new ASP.NET Core MVC application in the same solution. Then copy the Protos folder from the GrpcService1 project into the newly created MVC application. At this stage your Solution Explorer will look like this.

  • CRUD using gRPC, EF Core, and ASP.NET Core (Part - 2)

    In Part -1 of this article you created EmployeeCRUD service definition using Protocol Buffer language. The EmployeeCRUD.proto file and EF Core model is now ready. In this part you will create the EmployeeCRUD service based on the structure defined in the .proto file. To begin, open the project created in Part -1 and expand the Services folder. Rename the service file to EmployeeCRUDService.cs. At this point the Solutions Explorer will look like this.

  • CRUD using gRPC, EF Core, and ASPNET Core (Part - 1)

    If you have read about the new features of ASP.NET core 3.0, you are probably aware that it supports gRPC, a framework for building services using Remote Procedure Call (RPC). I won't go into the dry information about what gRPC is and how it can help you solve software problems in this article. This multipart article creates a simple yet complete example that performs CRUD operations on the Employees table of Northwind database. As you develop this example you will get chance to familiarize yourself with the basics of gRPC as implemented in .NET Core 3.0.

  • Push data to client using ASP.NET Core Web API and Server Sent Events

    Server Sent Events or SSE allow you to send push messages from the server to client. They come handy when you have a lengthy processing going on the server and want to notify the client from time to time about the status or intermediate results of the processing. In this article you will learn how SSE can be used to push data from Web API to the JavaScript client.

  • JSON to XML / XML to JSON conversion in .NET Core

    JSON is a preferred format for transferring data over the wire in modern web apps. However, at times you need to deal with XML data format. Moreover, you might want to handle JSON and XML in the same application. For example, you might be receiving data in JSON from a Web API and then you might want to feed it to another service that expects input in XML format. Such situations are common when you are integrating old and new software systems.

  • Upload Files Using jQuery Ajax and JavaScript Interop in Blazor

    Uploading files from client machine to the server is one of the fundamental operations in web applications. In ASP.NET Core MVC applications you can accomplish this task easily using HTML5 file input field and server side logic. However, Blazor doesn't have any built-in facility (so far) for uploading files. You either need to use some third-party solution or device your own technique to accomplish the task.

  • ASP.NET Core 3.0 - Ten features beginners should know

    If you are tracking the progress of ASP.NET Core, you are probably aware that .NET Core 3 and ASP.NET Core 3.0 are being released at .NET Conf 2019. There are many exciting feature additions and improvements to the latest version of ASP.NET Core. You might have already stumbled upon the prominent ones. In this article I am enumerating over ten features / improvements for beginners that are worth noting. My aim is to quickly mention them here so that you can explore them in more detail by visiting Microsoft's official channels such as product documentation and Channel 9.

  • Change Default Location of Views and Razor Pages in ASP.NET Core

    ASP.NET Core MVC web applications typically store view files under Views folder and Razor Pages are stored under Pages folder. Although this default location is what you want in most of the applications, at times you may want to store views and pages in some different folder. To that end this short article shows how to accomplish just that.

  • Use Azure Cache for Redis in ASP.NET Core

    Many ASP.NET Core application resort to caching for performance improvement reasons. I have discussed a few caching techniques in this, this, and this article. Additionally developers also use Azure Cache for Redis. It's a fully managed, high-performance in-memory caching service that you can utilize in your ASP.NET Core web applications. This article shows how.

  • Switch-less code : An Example in ASP.NET Core

    It is common in ASP.NET Core application to store one or more configuration options in appsettings.json. These options are then read inside MVC controllers or Razor Pages page models. Depending on a particular configuration setting you want to execute certain piece of processing. Although it sounds quite simple and straightforward beginners often end up doing this in a not-so-good way. To that end this article discusses a possible approach that is more flexible and helps you reduce the amount of future changes.

  • Authorize users with Azure Active Directory in ASP.NET Core

    In the previous article we discussed how to integrate Azure AD authentication in an ASP.NET Core web application. Continuing from where we left, this article shows how to authorize users based on their AD groups. First of all you need to create required groups in Azure AD and then assign one or more groups to a user account. So, open the Azure AD that you used last time and locate the Groups options as shown below.

  • Authenticate users with Azure Active Directory in ASP.NET Core

    ASP.NET Core web applications often need to authenticate users accessing the application. There are many authentication schemes you can use to accomplish this task. One of them is authenticating using Azure Active Directive (Azure AD). ASP.NET Core project templates provide an easy way to integrate Azure AD authentication in an application. However, there are a few steps you need to perform before going ahead with the integration process. To that end this article explains what those steps are and how to complete the integration.

  • Build your first Blazor client-side application

    In the previous article you learned to build your first Blazor server-side application. In this article you will develop the same data entry form using Blazor client-side application. Blazor client-side applications use WebAssembly (Wasm) to run. A WebAssembly capable browser downloads the Blazor application on the client-side and then executes it within the boundaries of the browser.

  • Build your first Blazor server-side application

    If you are tracking the progress of ASP.NET Core 3, you are probably aware that Blazor is getting a lot of attention and feature improvements. If you haven't developed Blazor applications yet it's worthwhile to take a quick look at the overall development process. To that end this article discusses a simple database update page build using server-side Blazor.

  • Use System.Text.Json for JSON processing in ASP.NET Core

    If you worked with earlier versions of ASP.NET MVC and ASP.NET Core, you are probably aware that these versions use Json.NET library for the sake of JSON processing. In ASP.NET Core 3 Microsoft has provided in-built support for JSON serialization and deserialization. That means you no longer need to depend on Json.NET library. The good part is, you can still use Json.NET if you so wish. So, you have two options now as far as JSON processing is concerned - either use in-built JSON API or use Json.NET. The in-built support for JSON serialization and deserialization comes from System.Text.Json namespace. In this article you will learn to use the System.Text.Json for serializing and deserializing JSON data during Web API communication.

  • Create and Use User Secrets in ASP.NET Core

    While developing an ASP.NET Core web application you often come across pieces of information that you wouldn't like to share with others. Consider, for example, a database connection string that contains a user ID and password. You typically store it in appsettings.json file. But when you share your project code with others (say through a version control system) those details are also shared with others. Another example could be access keys or API keys. You might not want to share these details with others. Luckily, ASP.NET Core and Visual Studio provide an easy way to deal with this requirement through what is known as User Secrets.

  • Multiple implementations of an interface in ASP.NET Core DI container

    If you worked with ASP.NET Core before chances are you used ASP.NET Core's dependency injection features. Most commonly you register a single implementation of an interface as a service type. However, at times you may want to register multiple implementations of an interface as service types. In this article you learn how to accomplish the task.

  • Dealing with MongoDB DateTime in ASP.NET Core

    MongoDB is one of the popular NoSQL databases available today. You can use MongoDB database in your ASP.NET Core applications using MongoDB.Driver NuGet package. I discussed the basics of MongoDB including CRUD operations here and here. Document databases such as MongoDB store data as JSON documents. Although JSON supports basic data types such as string, number, and boolean JSON doesn't support DateTime. So, date-time values are stored as string. In this article we will discuss a few things that you need to take into account while storing date-time values.

  • Use Cache and Distributed Cache Tag Helpers in ASP.NET Core

    Web developers often look for opportunities to boost the performance of their web applications. ASP.NET Core provides server side caching in the form of in-memory and distributed cache implementation. Moreover, it offers two Tag Helpers to implement cache HTML content of razor views or razor pages - Cache and Distributed Cache. To that end this article discusses these Tag Helpers in brief.

  • Enable CORS in ASP.NET Core API

    Browsers do not allow cross origin communication for security reasons. This means if an ASP.NET Core web API housed in one web app is called by JavaScript code running as a part of another web app, the communication attempt will fail. However, you can alter this default behavior by adding some configuration in your API application. To that end this article discusses how that task can be accomplished.

  • JWT Authentication in ASP.NET Core using jQuery Client

    In my previous article we discussed what JWT authentication is and how to implement it in ASP.NET Core APIs. In that article you learnt to use Postman tool to test the JWT functionality. In most of the real-world cases you will be handling the JWT using either client side script (jQuery, Angular etc.) or server side code (HttpClient component). To that end this article discusses using jQuery to consume the SecurityController and EmployeeController we developed earlier.