Thoughts on .Net & Coding

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

  • Use [Controller] and [NonController] Attributes in ASP.NET Core

    ASP.NET Core MVC uses certain conventions when it comes to naming the controllers. Although these defaults work as expected in many cases, at times you may want to take charge of the controller naming. Luckily, ASP.NET Core provides two attributes - [Controller] and [NonController] - that can be used to alter this default behavior. To that end this article shows how to use these attributes with simple examples.

  • Upload Large Files in ASP.NET Core

    By default, ASP.NET Core allows you to upload files approximately 28 MB in size. However, at times you want to deviate from this limit and upload larger files on the server. To raise this limit you need to make a couple of additions to your code. And there are a few variations of how that can be done. To that end this article discusses these possible approaches to upload large files.

  • Use Angular Component as Element, Attribute, and Class

    Components are building blocks of any Angular application. Most commonly Angular components exist as custom markup elements in the template. However, that's not the only way to use components. You can also use them as if they are an attribute of an HTML element. Or you can also use them as the value of class attribute on HTML elements. Using Angular selectors you can decide how a component will be used in the template markup. To that end this article illustrates each type of usage with a simple example.

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