Thoughts on .Net & Coding

.Net Articles, tutorials, reviews, code and more...

  • Store ASP.NET Core Application Configuration in Multiple Files

    ASP.NET Core applications typically store configuration information in appsettings.json file. Although this default arrangement works in many situations, at times you need to store your application configuration in multiple physical files. Luckily, storing configuration in multiple files is not a big deal since ASP.NET Core by design supports this feature. However, you need to be aware of a few things involved in the process. This article discusses just that.

  • 7 Things Worth Knowing About ASP.NET Core Logging

    Logging is an important aspect of any professional web application. You often need to log data, information, errors, system events, and such things. ASP.NET Core comes with a set of inbuilt logging components that you can use for this purpose. To that end this article enumerates through seven things that are worth knowing about ASP.NET Core logging.

  • Use HTML5 download attribute to download a URL

    The anchor element allows you to render a hyperlink to a resource using its href attribute. There is a lesser known attribute of the anchor element - download - that can come handy in certain situations. The download attribute instructs the browser to download the resource as mentioned in the href attribute. Moreover, you can also specify the default file name for the download.

  • Utilize Server Sent Events (SSE) in ASP.NET Core

    Some web applications application need to show data in real-time. As soon as the data is made available at the server, it immediately needs to be displayed to the end user. Traditionally developers used to poll the server periodically to check if a new data is available. This approach has its own drawbacks and may prove to be unsuitable in certain cases. Wouldn't it be nice if server notifies the client of new data rather than client checking with the server periodically? That is what HTML5 Server Sent Events (SSE) allow you to do. In this article you will learn what Server Sent Events or SSEs are and how to develop a ASP.NET Core application that receives real-time data from the server.

  • Create View Components in ASP.NET Core

    ASP.NET Core offers several ways to reuse your code and UI. One of them is View Components. Simply put a view component is a bundle of C# code, Razor code, and markup that occupies some screen real-estate. Unlike partial views a view component is more like a standalone widget housed in a view.

  • Implement Cookie Authentication in ASP.NET Core

    If you have been working with ASP.NET Core, you are probably aware of ASP.NET Core Identity. ASP.NET Core Identity is a full-fledged framework to secure your websites. It comes with a lot of features such as external logins and Json Web Tokens (JWT) support. Ay times, however, you need something that is simple and gives you total control on various aspects of implementation such as data store and account manageemnt. That is where ASP.NET Core's Cookie Authentication can come handy. In this article you will learn what Cookie Authentication is and how to configure it to secure your websites.

  • Use Ajax to perform CRUD operations in ASP.NET Core Razor Pages

    ASP.NET Core Razor Pages offer a simple page based programming model for the developers. A razor pages consists of a .cshtml files and associated page model class. The page model class can house actions to handle HTTP verbs. For example, a page model class can contain OnGet(), OnPost(), OnPut(), and OnDelete() actions to deal with GET, POST, PUT, and DELETE verbs respectively. This sounds straightforward as far as requests are initiated by a form. However, things are bit tricky while making Ajax calls to a razor page. To that end this article illustrates how to develop a razor page that performs CRUD operations using Ajax calls.

  • Various ways of accessing DI services

    ASP.NET Core provides an inbuilt Dependency Injection framework that you can utilize to register and access services. One of my earlier article explains various lifetime options that you can use while registering a service. Once a service is registered with the DI container you can get an instance of the service using what is known as constructor injection. Although constructor injection is the most common way of accessing the registered services, there are a few more options that can be used to accomplish the task. To that end this article discusses these alternatives with a simple example.

  • Use Razor Pages, MVC, and Web API in a single ASP.NET Core application

    If you are worked with ASP.NET Core 2.0 before you are probably aware that Visual Studio 2017 offers three basic project templates for creating ASP.NET Core 2.0 projects. They are Web Application (Razor Pages), Web Application (MVC), and Web API (see below). Interestingly Web Application project defaults to Razor Pages. It is important for the beginners to be aware that although these are three different project templates, you can have all these development options - Razor Pages, MVC, and Web API - inside a single ASP.NET Core web application.