Skip to main content

Posts

Showing posts with the label Asp.NetCore6

Blazor Server Authentication And Authorization Using Microsoft AspNetCore Identity[.NET6]

In this article, we are going to do a small demo on Blazor Server authentication and authorization using Microsoft AspNetCore Identity. Microsoft AspNetCore Identity Library: AspNetCore Identity: Built-in login functionality library that supports authentication of all different .NET applications. Provides rich authentication UI pages and customizable as well. Adoptable for External Authentication providers like 'Google', 'Facebook', 'Outlook'. Can be integrated with other authentication like 'IdentityServer4', 'Azure Active Directory', 'Azure Active Directory B2C(Azure AD B2C)'. Create A .NET6 Blazor Server App With Individual Authentication: Let's create a .Net6 Blazor Server sample application with individual authentication to accomplish our demo. We can use either Visual Studio 2022 or Visual Studio Code(using .NET CLI commands) to create any.Net6 application. For this demo, I'm using the 'Visual Studio Code'(using

Blazor Server CRUD Operation Using MudBlazor UI Components[.NET6]

In this article, we are going to implement CRUD operation in .NET6 Blazor Server application using the MudBlazor UI components. Blazor Server: Blazor Server is a single-page application. At the server, a pre-rendered HTML output of the page will be delivered to the user browsers. Any UI update, event handling, javascript calls will carry over by a SingnalR connection to the server. So application updates are depending on the continuous connection of the SignalR. So Blazor server is a single-page application that can be made of C#. Since the blazor server only outputs the pre-rendered HTML to the client, so there is no c# code downloading into user browsers like in Blazor WebAssembly(c# code downloaded and run in the browser for blazor webassembly application). SignalR Connection: A Blazor Server application works over a SignalR connection. A Blazor Server application creates a UI State memory at the server which will be interacted by the SignalR connections. If a SignalR conn

Minimal API 'Result.Stream()' Return Type[.NET6]

In this article, we will know about a Minimal API return type that is 'Result.Stream()' Result.Stream(): The 'Result.Steam()' can be used to deliver the stream of data as a response from the Minimal API endpoint. For example on consuming a third-party API from our minimal API endpoint, a common approach is to read the response from the third-party API and then deserialize the response and finally return the response using 'Result.Ok()'. But using 'Result.Stream()' return type we can directly return the stream of third-party API response without deserializing. Create A .NET6 Minimal API Project: Let's create a .Net6 Minimal API sample project to accomplish our demo. We can use either Visual Studio 2022 or Visual Studio Code(using .NET CLI commands) to create any.Net6 application. For this demo, I'm using the 'Visual Studio Code'(using the .NET CLI command) editor. CLI command For Minimal API Project dotnet new webapi -minimal -o Your_

Implement IResult For Custom Response In Minimal API[.NET 6]

In this article, we will understand the implementation of IResult for custom response in minimal API[.NET6]. IResult Type: In minimal API to return a custom response, we have to implement the 'Microsoft.AspNetCore.Http.IResult'. class CusomtResult : IResult { public Task ExecuteAsync(HttpContext httpContext) { throw new NotImplementedException(); } } The 'ExecuteAsync' method gets automatically invoked, the only parameter it will have is the 'HttpContext' where we can use to append our custom response type. Create A .NET6 Minimal API: Let's create a .Net6 Minimal API sample project to accomplish our sample. We can use either Visual Studio 2022 or Visual Studio Code(using .NET CLI commands) to create any .NET6 application. For this demo, I'm using the 'Visual Studio Code'(using .NET CLI commands) editor. CLI command For Minimal API Project dotnet new webapi -minimal -o Your_Project_Name Implementing Custom Response W

.NET Application Controller Actions Now Support Asynchronous Streaming Response[.NET6 Feature]

In this article, we will know about .NET6 feature that is MVC/API controller actions now supports the asynchronous streaming response. Async Stream: A data stream is often retrieved or generates elements asynchronously is 'Async Stream'. Now from .NET6 we can output the async stream of response from the controller's actions. An action method that contains return type 'IAsyncEnumerable' no longer buffers the response content in application memory before it sends to the clients. So not buffering help to reduce the application memory usage when returning large dataset result that can be asynchronously enumerated. Sample Action Method That Returns 'IAyncEnumerable<T>' Results: Let's write a sample code that can return the asynchronous stream of data. [Route("Test")] [HttpGet] public async IAsyncEnumerable<int> GetNumbers() { for (int i = 1; i < 100; i++) { await Task.Delay(10); Console.WriteLine(i); yield return i;

SupplyParameterFromQuery Attribute To Read Query Parameters In Blazor Application[.NET6 Feature]

In this article, we will know about .NET6 feature like 'SupplyParameterFromQuery' attribute to access the query parameters in the blazor application. SupplyParameterFromQuery Attribute: A routable component to capture the query parameter values into the component parameter, then we have to decorate the 'SupplyParameterFromQuery' attribute along with the 'Parameter' attribute on top of the component parameter. On decorating 'SupplyParameterFromQuery', then the component parameters can read the query parameters of type 'bool', 'datetime', 'decimal', 'float', 'guid', 'int',  'long', 'string'. It also read the array type of query parameters as well. If component parameter name and query parameter name then there is no need for explicit mapping to read the values. If the component parameter name and query parameter name are different then we have to specify the query parameter in an attribute lik

.NET6 Application No Longer Generates A Separate Assembly For Views By The Razor Compiler[.NET6 Feature]

In this article, we will understand a .NET6 feature that is in a .NET6 application no longer generates a separate assembly for views(.cshtml file) by the razor compiler. .NET5 Or Below Version Generates Separate Views(.cshtml) Assembly:  For .NET5 or below versions razor compiler produces a separate views assembly that contained views and pages(.cshtml files) in the UI application. .NET6 No Separate Views Assembly File: From .NET6 razor compiler builds the views and pages(.csthml) into the UI project assembly itself. This change improves the application build performance, enables single file deployment, and enables these types to work for the Hot Reload(Developers option to reflect changes immediately). Video Session: Wrapping Up: Hopefully, I think this article delivered some useful information on a .NET6 feature no separate assembly file generation for views(.cshtml files). I love to have your feedback, suggestions, and better techniques in the comment section below. Supp

.NET 6 Application No Need To Configure Developer Exception Page Middleware Explicitly[.NET6 Feature]

In this article, we will get to know about a feature of .Net 6 that is 'no need to configure developer exception page middleware explicitly because the framework will automatically enable developer exception page for the Development environment'. .NET 5 or Below Version Application Developer Exception Page Middleware: For bugs identification, the developer exception page is very helpful for debugging. For .NET5 or Below version application developer exception page middleware is always configured in the 'Startup.cs' file based on the environmental variable that is 'Development'. Startup.cs: This middleware renders a well-designed exception page with a full exception stack trace as below. .NET6 Application: From .NET6 application no need to configure developer exception page middleware explicitly. By default, the framework will load the developer exception page if the environment variable is 'Development'. Program.cs: But still, we can see the deve