Thoughts on .Net & Coding
.Net Articles, tutorials, reviews, code and more...
-
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.
-
Handling Multiple Submit Buttons in Razor Pages
Razor Pages in ASP.NET Core allow you to build page focused web applications using simple page based programming model. If you worked with Razor Pages before you are probably aware that by default you can handle requests using methods such as OnGet(), OnPost(), OnPut(), and OnDelete(). This means a form POSTed to the server needs to be handled using only one action - OnPost(). At times, however, you need to have multiple actions to deal with the same HTTP verb. A common scenario is when you have multiple submit buttons on a form.
-
Use Cookies and Session To Store TempData In ASP.NET Core
If you ever used TempData in ASP.NET MVC, you are probably aware that by default TempData is stored in Session state. This means the web application must have sessions enabled. Luckily, ASP.NET Core 2.0 provides two TempData providers - Cookie based and Session State based. To that end this article shows how to use both of them in an ASP.NET Core application.
-
Support Multiple Versions of ASP.NET Core Web API
Now a days REST APIs are quite commonly used in web applications. At times you may need to provide multiple versions of your API to the clients. This could be because of enhanced functionality exposed by the API or it could for the sake of offering multiple sets of functionality (basic, advanced, free, paid etc.). This article discusses a few approaches for offering such multiple versions of your API to the client applications.
-
Use BindProperty Attribute for Model Binding to Properties
Model binding allows you map request parameters to actions. This means action methods will have one or more parameters and those parameters will receive their values from the model binding framework. Model binding can be performed to simple types as well as complex types. In ASP.NET Core 2.0 you can perform model binding to properties in addition to action parameters. This article explains how.
-
Seed Users and Roles Data in ASP.NET Core Identity
ASP.NET Core identity allows you to implement authentication and authorization for your web applications. While working with ASP.NET Core Identity at times you need to create default user accounts and roles in the system. In ASP.NET MVC you could have easily done this in Global.asax and Application_Start event handler. In ASP.NET Core the process is bit different since the application startup process is different. To that end this article explains a way to seed such user and roles data in your applications.
-
Drag-n-Drop File Upload in ASP.NET Core
In one of my earlier articles I discussed how to upload files using full page post-back as well as Ajax post-back. Usually developers use the file input field to select one or more files to be uploaded from the client machine. However, you can also HTML5 drag-n-drop to make it east for the end user to pick files directly from Windows explorer. To that end this article shows how to implement just that.