
Image by awcreativeut
MVC Filters are discussed in detail at docs.microsoft.com
Filters in ASP.NET Core allow code to run before or after specific stages in the request processing pipeline.
Image by awcreativeut
MVC Filters are discussed in detail at docs.microsoft.com
Filters in ASP.NET Core allow code to run before or after specific stages in the request processing pipeline.
Image by awcreativeut
CORS are best described on MDN
Cross-Origin Resource Sharing (CORS) is an HTTP-header based mechanism that allows a server to indicate any origins (domain, scheme, or port) other than its own from which a browser should permit loading resources. CORS also relies on a mechanism by which browsers make a "preflight" request to the server hosting the cross-origin resource, in order to check that the server will permit the actual request. In that preflight, the browser sends headers that indicate the HTTP method and headers that will be used in the actual request.
CORS in .NET6 API can be configured using CORS policies.
Image by awcreativeut
A blog post is in progress.
A Channel by merriam-webster refers to among other meaings
the bed where a natural stream of water runs
I will start this post by adopting the water channel analogy to explore how it relates with C# System.Threading.Channels
.
Image by @claybanks
Authorizing the resource access is essential part of any API. The .NET provides you a perfect mental model which is easier to reason about. It has this flow:
IAuthorizationRequirement
interface.AuthorizationHandler<UniqueIdHeaderRequirement>
and register it.Then Authorize
attribute allows you to set a policy name when used on controller or action method.
But if you are fan of Minimal API then fluent style is the way to go using RequireAuthorization
.
When the application expects Unicode characters as input from the user, it is best to normalize it before storing it in the database, especially when you plan to use the information for comparison.
Suppose the application asks the user to upload a file with the same name as their first name, which contains the character é. If you validate the file name using the string comparison (===) operator or comparing length, it will fail if different Unicode code points represent the input.
You validate the client-side and server-side using C# as a best practice. It would be best to normalize the string before comparing; otherwise, the validation will fail either at the server or client side.
Browser's behavior is different for the Unicode characters; some do the normalization, and some do not. I recently had to fix an issue where string comparison without normalization only failed when the user uploaded the file using Chrome or Firefox on Mac. One such example is on here.
Some unicode character like ñ can be represented by using one code point (\u00F1) or two code points (\u006E\u0303). Such characters visually looks exactly the same but will have different string length. Thus string equality comparison and length tests will fail. This MDN and .NET article(s) describe it beautifully. If you are expecting unicode characters as an input from the user, store it after normalizing.
Variance means change. The concept of change applies to reference types of objects in C#. Behavior changes in objects are observable in two ways:
Image by awcreativeut
The word Host will repeatedly appear in the post so let's briefly understand what it means?
The Host is a container which offers rich built-in services such as Dependency Injection, Configuration, Logging, Host Services and others. The NET 6 offers Generic DefaultHost which can be configured to handle the activities as per your use case. Two major variations of the Host are:
Think of it as Airbnb Host who keeps the property ready to serve when the guests arrive. The property offers a different set of services and allows you to bring your own services. The lifetime of such services depends upon the contract, which the Host controls.
var host = Host.CreateDefaultBuilder(args) //WebHost.CreateDefaultBuilder(args)
.ConfigureLogging( (context, builder) => builder.AddConsole())
.Build(); // Build the host, as per configurations.
await host.RunAsync();
A service that performs the work in the background mostly does not offer an interface to interact. In technical terms, any reference type object which implements the IHostedService
interface is a background/hosted/worker service.
Terms such as Worker, Windows Service, and Background Task refer to HostedService based on context. In Windows Server, Widows Service is how you deploy a Hosted Service. Background Task or Hosted service runs as part of .NET Web Host, and it runs in the same operating system process.
SQL Server Enterprise offers scalable memory optimized relational tables. Yes, all data inside table will be loaded in memory. In-Memory tables has two flavors.