Posts

Step by step migration of ASP.NET Core 2.2 to 3.1

In order to upgrade/migrate asp.net core version to 3.1 following steps to be perform.
Download and install Visual Studio 2019 version 16.4 or higher.Download and install .NET Core 3.1  https://dotnet.microsoft.com/download/dotnet-core/3.1Upgrade the projects of solution to .NET Core 3.1 , because ASP.NET Core 3.1 requires it.Update existing Nuget packages to a version compatible with ASP.NET Core 3.1 in each projectUse IHost interface from a IHostBuilder instead of building and running a IWebHost from a IWebHostBuilder in Program.cs public static IHostBuilder CreateWebHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseKestrel() .UseSerilog() .UseStartup<Startup>(); }) Change AddMvc method has been replaced by AddControllers in Startup.cs of each projects.In Startup.cs,UseMvc method to be replaced by…

Introduction of Asp.net MVC Basics for beginners

MVC is an architectural pattern which separates the representation and user interaction.
It's divided into three broader sections,

ModelViewController. 
Below is how each one of them handles the task.
View : The View is responsible for the look and feel.
Model: Model represents the real world object and provides data to the View.
Controller: The Controller is responsible for taking the end user request and loading the appropriate Model and View.

Advantages of ASP.NET MVC


Extensive support for TDD. With asp.net MVC, views can also be very easily unit tested.Complex applications can be easily managedSeparation of concerns. Different aspects of the application can be divided into Model, View and Controller.ASP.NET MVC views are light weight, as they do not use view-state.It provides extensive support for URL Routing that helps to make friendly URLs (means friendly for human as well as Search Engines).Support for existing ASP.NET features like membership and roles, authentication and authoriz…

How to ping Azure VM using C# code explained

I was looking for the code which can ping the Azure VM and give me the details whether VM is UP or down since the ICMP protocol is not permitted through the Azure load balancer,
you will notice that you are unable to ping an Azure VM from the internet, and from within the Azure VM, you are unable to ping internet locations.

To get rid of the issue i digged the internet to get the solution so finally i got the below solution which I have contructed through the function,
below function will ping the azure vm machine and returns true if online or false if offline

public static bool PingServerWithSocket(string iporHostname,int portNo)
        {
            bool result = false;

                try
                {
                    var sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                    sock.Blocking = true;

                    IPAddress ipaddes = Dns.GetHostEntry(iporHostname).AddressList[0];
                    sock.Connect(ipaddes, portNo);
   …

Regular expression for validating URL in Javascript

I was looking for a decent regular expression to validate URLs that were entered as user input with.
After lots of searching on google i got the perfect solution which satisfy my requirement of my current assignment
Following is the regular expression for validating URL (Valid URL Regular Expression) a have used which worked perfectly.

^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\(\)\*\+,;=.]+$

Following is the pattern results for the same
https://www.test.com   -Passedhttp://www.test.com   -Passedwww.test.com   -Passedtest.com   -Passedhttp://blog.test.com   -Passedhttp://www.test.com/product   -Passedhttp://www.test.com/products?id=1&page=2   -Passedhttp://www.test.com#up   -Passedhttp://255.255.255.255   -Passed255.255.255.255   -Passedhttp://invalid.com/perl.cgi?key= | http://web-site.com/cgi-bin/perl.cgi?key1=value1&key2   -Failedhttp://www.site.com:8008   -Passed
Comment if you like it!!

Devexpress Datebox date formatting in angular 6 with example

The Devexpress DateBox in Angular is a widget that displays the date and time in one of DevExtreme predefined formats or a format defined in an
external localization library, or a type in the required date/time value. In this article,
the i will provide you different date-format which we can set on DateBox to show date and time to user.

Following is the code snippet to add Datebox in your Angular form if the you want to capture only date


<dx-date-box [value]="now" displayFormat="EEEE, MMM dd" type="date" > </dx-date-box>

Following is the custom formats we can set and depending upon its converted values will be shown.

"dd-MM-yyyy" => 28-10-2018 "EEEE, MMM dd" => Sunday, Oct 28 "dd MMM yyyy EEEE" => 28 Oct 2018 Sunday "dd-MM-yyyy EEEE" => 28-10-2018 Sunday
alternatively you can change the format as way you want


Following is the code snippet to…

Angular User Session Timeout example step by step

Image
This functionality let the user know that their session is about to expire and that they would be logged out if they didn’t take action. I have written this functionality in Angular for my latest application. 

If you are new to Angular 6 then read my article about Setting up Angular 6 step by step before jump to this article to get handy in Angular 6.




Dealing with timers in Angular can be significantly different when using React components and subscriptions. The basic premises remains the same, though. We’ll have a service with a timer that will provide a Subject to which consumers of the service can subscribe. A React Subject provides an easy mechanism to trigger a “next” subscription to alert consumers that the timer has expired.


import{ Injectable } from '@angular/core';
import{ Observable, Subject, Subscription, BehaviorSubject} from 'rxjs/Rx';
@Injectable()
exportclassIdleTimeoutService {
private_count: number = 0;
private_serviceId: string = 'idleTimeoutS…

How to upload a file from Angular 6 to ASP.NET Core 2.1 Web API Application step by step

Image
This post talks about how to upload a file from Angular 6 to ASP.NET Core 2.1 Web API. 

First thing first, let’s create an Angular 6 app with Visual Studio 2017. To do that, open Visual Studio 2017  community edition , hit Ctrl+Shift+N and select the ASP.NET Core Web Application (.NET Core) project type from the templates. When you click Ok, you will get the following prompt,



Make sure to select “ASP.NET Core 2.1” from the version dropdown and choose Angular. The Visual Studio will create an ASP.NET Core 2.1 based project with Angular 6 configured. This should create an Angular 6 app. You should run the app to make sure that there are no errors.
Create Upload API in ASP.NET CoreTo support uploading on the server, add a Web API controller named UploadController in the Controller folder. This controller has the API to upload the file and store it at a location. Add the controller with the following code.


using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Syste…