Skip to main content

Posts

Showing posts with the label Asp.net core 3.0

.Net Core Session Management

The Session helps to store user data in the application memory. Since the user data stores on the application it quick and fast to access. .Net Core Session data stored application using the cache, this cache can be either In-Memory or Distributed Cache.  Session Work-flow: On the user request the application from the browser, the server will create a session with an id called Session-Id.  This Session-Id will be given to the user in response by storing it in the cookie. So on every next request, this cookie will reach to the application which contains Session-Id.  An application uses the SessionId as the main key and stores all user data in the application cache. So by receiving a cookie from a client with Session-Id application will fetch the session stored data as per request.  This cookie session is browser-specific it is not sharable between browsers.  We can set session time out in our application, where after the time session data will get automatically cleared. Create A Sample

.NET Core MVC Application File Upload To Physical Location With Streaming Technique(Useful For Large Files) - Part 2

In  Part 1 we have explored how to upload large files to a server using Streaming Technique. A complete .Net Core sample application has been developed from scratch to understand the file upload. Also discussed on custom model binding manually from the raw form data as well as triggering model validation. I recommend understanding  Part 1 is essential before jumping here.  AJAX Call To File Upload(MVC or Web API): Let's develop an action method that displays a form with a file upload field. Controller/AjaxFileUploadController.cs: using Microsoft.AspNetCore.Mvc; namespace StreamFileUpload.App.Controllers { [Route("ajax-file-upload")] public class AjaxFileUplaodController : Controller { [Route("add-file")] public IActionResult AddFile() { return View(); } } } Let's develop the form that posts the data using the AJAX call. Views/AjaxFileUpload/AddFile.cshtml: <div> <form action="

.NET Core MVC Application File Upload To Physical Location With Streaming Technique(Useful For Large Files) - Part 1

Streaming Technique In File Upload: Streaming Technique is useful in uploading the larger files. Uploading file is achieved as a multipart request where the files are processed directly by the application. In Streaming Technique file uploading can not be done with Model Binding(but in buffered technique, files uploading can be done with Model Binding by using IFormFile type). So the file is accessed directly from the request object(as multipart request) and processed. Since Model Binding will not work here every filed from the form that is like text fields, file uploading fields, etc are received as 'form-data' format in the multipart request. Streaming helps in scaling the application. Streaming doesn't demand memory or disk space(but in buffered technique, file upload highly depends on the RAM, which doesn't work for large file uploading). Note: Click here for file uploading using buffer technique Create A Sample MVC Application: Let's understand

Endpoint Routing In Asp.Net Core

How Routing Works In  Core 2.1 And Below Versions?: In Asp.Net Core routing is configured using app.UseRouter() or app.UseMvc() middleware. app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); Here in Dotnet Core version 2.1 or below versions on the execution of route middleware request will be navigated appropriate controller matched to the route. An operation or functionality which is dependent on route URL or route values and that need to be implemented before the execution of route middleware can be done by accessing the route path from the current request context as below app.Use(async (context, next) => { if(context.Request.Path.Value.IndexOf("oldvehicle") != -1) { context.Response.Redirect("vehicle"); } else { await next(); } }); app.UseMvc(routes => { routes.MapRoute( name: "vehicleRoute", template: "vehicle", defaul

Asp.Net Core MVC Form Validation Techniques

Introduction: Form validations in any applications are like assures that a valid data is storing on servers. All programing frameworks have their own individual implementations for form validations. In Dotnet Core MVC application server-side validations carried on by the models with the help of Data Annotations and the client-side validations carried by the plugin jQuery Unobtrusive Validation. jQuery Unobtrusive Validation is a custom library developed by Microsoft based on the popular library  jQuery Validate . In this article, we are going to learn how the model validation and client-side validation works in Asp.Net Core MVC Application with sample examples. Getting Started: Let's create an Asp.Net Core MVC application project using preferred editors like Microsoft Visual Studio or Microsoft Visual Studio Code. Here I'm using Visual Studio. Let's create an MVC controller and name it as 'PersonController.cs' and add an action method as bel