Thoughts on .Net & Coding

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

  • Create Custom Client Side Validation Attribute in ASP.NET Core

    ASP.NET Core comes with a set of validation attributes that can be used to perform basic validations in your application. At times the inbuilt validation attributes doesn't meet your requirements and you need something customized as per your validation criteria. Luckily, you can easily create your own validation attributes that perform client side as well as server side validations. This article shows how.

  • Perform Remote Validation in ASP.NET Core

    While performing model validation, at times you need to validate values entered in client side controls against server side data. Such a validation is called remote validation. As you might have guessed remote validation uses Ajax to validate the data. Thus validation is initiated on the client side but performed on the server side. The outcome of the validation process is sent back to the client so that the end user can be notified accordingly. In this article we will learn to implement remote validations in ASP.NET Core MVC and ASP.NET Core Razor Pages.

  • Allow only Ajax requests for an action in ASP.NET Core

    ASP.NET Core offers attributes such as [HttpGet] and [HttpPost] that allow you to restrict the HTTP verbs used to invoke an action. You can also use HttpRequest object's Method property to detect the HTTP verb behind the current request. However, at times you need to know whether a request is an Ajax request or not. You may also need to restrict an action only to Ajax calls. Although thee is no inbuilt way to accomplish this task, you can easily implement such a feature in your application. This article discusses how.

  • Detect code changes and restart application using .NET Core file watcher

    When you run a ASP.NET Core application using dotnet run CLI command, the application is started for you and made available at a specific URL and port. During development stage it's very common to make changes to C# code such as models, controllers, and other classes. To see these modifications in action you need to stop the application and again execute the dotnet run CLI command. Wouldn't it be nice if there is some way to detect such code changes and re-start the application automatically? Luckily, there is a tool called file watcher that does the trick. Let's see how.

  • Multiple GET and POST methods in ASP.NET Core Web API

    In ASP.NET Core MVC and Web API are parts of the same unified framework. That is why an MVC controller and a Web API controller both inherit from Controller base class. Usually a Web API controller has maximum of five actions - Get(), Get(id), Post(), Put(), and Delete(). However, if required you can have additional actions in the Web API controller. This article shows how.

  • 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.