Articles and tutorials on .NET Core, ASP.NET MVC, Kendo UI, Windows 10, Windows Mobile, Orchard

  • Make Your HTML Pages Dynamic Using Handlebars Templating Engine

    Technologies and methods for designing and developing web pages have come a long way and with a plethora of tools available at one's disposal, getting a minimal website is not a rocket science anymore. As web developers, we often face a dilemma to go for a static site using plain HTML or to go for a dynamic one with some server-side programming stack. Both of the approaches has got advantages as well as disadvantages. 

     If we go for a static one, the advantages are  

    1. Time needed for development is less.
    2. Easy to create and less expertise is needed 
    3. Site will be super fast 

     Disadvantages,  

    1. Hard to maintain 
    2. Lot of repetitive work 
    3. Hard to scale 

     And for the dynamic approach, advantages are 

    1. Easy to maintain 
    2. Repetitive work can be avoided 
    3. Scaling is easy and more features can be easily integrated 

     Disadvantages 

    1. Dedicated personal  is needed 
    2. Cost factor increases 

    We can overcome some of the cons mentioned above by applying JavaScript Templating. JavaScript Templates helps to segregate HTML code and content which it is rendering in the browser. This separation of concerns helps to build a codebase which is easy to maintain in the future, modifications can be easily done with minimal disruption to the existing codebase. 

    Some of the most popular JavaScript templating engines are Mustache, Underscore, EJS, and Handlebars and in this post, I am going in detail to show how we can make of Handlebars to generate HTML content from the template. 

    Categories: Web Developement, Client Side

  • How to a create a private Docker registry in Azure

    The containerization technology has been around for some years, but it only came to the forefront when a company called Docker released their toolset which is also called Docker. Just like what shipping containers did to the logistics industry, docker revolutionized the way which we shipped software. Along with the tooling, they also created a public registry called Docker Hub to store the images created using the toolset. It's free and open to all, but in some case such as enterprises building their own proprietary software doesn't want to keep it in a public domain. So to avoid this Docker supports private registries also and it can reside in on-premises servers or in the cloud. In this post, I am going to show how can we create a private registry in Azure, Microsoft's cloud platform and then to use it for pushing and pulling images from it.

    Pre-Requisites

    1. An Azure Subscription
    2. Somewhat familiarity in Azure
    3. Beginner level knowledge in using Docker

    I have already written an article about creating an image and a container based on it using Docker, please feel free to refer it if want to get a quick refresher.

    Setup

    In this post, I will be using the Azure Cloud Shell which is available on the portal to run all the commands. If you are hearing it for the first time, please refer the official documentation here. It basically gives a browser-based shell experience and supports both Bash and PowerShell. You can also the portal or Azure CLI for the same.

    Categories: Docker

  • Hosting a ASP.NET Core application in a Docker container using microsoft/aspnetcore image

    You all will be familiar with Docker by now given its popularity among developers and infra people and some of you may have already created containers using Docker images. One of the most widely used workflows among people using .NET Core will create a new web application by using the dotnet new command as shown below.

    The below example uses ASP.NET Core 2.0 framework, in which the dotnet new command will create the project as well as restores the dependencies specified in the csproj file by default. I have already written a post about it and you can refer it for information about it

    Then you will do a build to see if there are any errors and use dotnet run command which will self-host the web application

    Categories: DevOps, ASP.NET Core, Docker

  • What's changed with new command in .NET Core 2.0

    Microsoft has released a major revision to the .NET Core framework around mid of August bumping the version to 2.0. This release includes not only the upgrade to the core framework but also include ASP.NET Core 2.0 and Entity Framework 2.0. Also along with this .NET Standard 2.0 is also released and it's now supporting around 32K + APIs and is a huge leap from what we had until now. You can read more about it by going to the announcement here.

    One of the changes among these is that the dotnet restore is now an implicit command which means that there is no need to execute the restore command explicitly for commands which needed to do a restore before executing it. 

    For example in .NET Core 1.1 whenever we executed a dotnet new command for creating a project we needed to execute the restore command before doing a build or execution. With .NET Core 2.0 when we execute the new command, the restore is now run automatically as part of the tooling. The following are the list of the commands which have got implicit support for restoration.

    new
    run
    build
    publish
    pack
    test

    Categories: ASP.NET Core

  • Getting Started with Angular Development Using Cloud9 Online IDE

    Cloud 9 is an online IDE hosted in the cloud and runs inside the browser. It's built on top of a Linux container and offers most of the features found in a standalone IDE. To start using it, one needs to create an account at Cloud 9 website. Once you created the account, you will be able to create workspaces as per your development needs. Given below is the screenshot of the IDE which I created for web development.

    For using Cloud9 or c9 in short for all your development needs, you will need to create a workspace based on the Blank template as shown below

     

    Categories: IDE, Web Developement

  • Generate C# Classes from a JSON String Easily Using Visual Studio

    As developers, we are often faced with certain tasks that are very repetitive in nature, which can also be time consuming to solve it. For example, whenever we need to reserialize a complex JSON string to classes we may need to write a lot of code. Until recently, whenever I needed to do such task I invariably create the classes manually and if it's a complex string, I was spending way too much time on that.

    When the instances like these began to happen every now and then, I decided to search for online options which can spit out classes from a JSON string. After some googling, I found out this site json2csharp.com which can do what I was looking for. You only need to paste the JSON in the input box and click on the Generate button to get the classes in C#.

    Categories: C#, Visual Studio 2015 Tips & Tricks, Windows 10

  • Bug : dotnet CLI Template Engine Produces Invalid Code if Name of the Directory is a Valid C# Keyword

    With the release of .NET Core 1.0 tooling, dotnet new make use of the templating engine to generate various types of projects like Console App, Web App, WebAPI etc. If you are not aware of it, please read my earlier post on it here.

    Categories: DotNet CLI, Web Developement, MVC

  • Stream Video Using Azure Media Services

    Recently I faced some dilemma in setting up video streaming for a site which I was working on. Since most of the targeted audience was from the enterprises, I wanted to avoid YouTube and other popular streaming services because of the greater possibility of it getting blocked by the corporate firewalls. So after some research, I found that the offering from Microsoft Azure very interesting and decided to explore it further. So in this post, I will be going through the various steps for setting up video streaming using Azure Media Services.

    From the documentation, Azure Media Service is

    An extensible cloud-based platform that enables developers to build scalable media management and delivery applications. Media Services is based on REST APIs that enable you to securely upload, store, encode and package video or audio content for both on-demand and live streaming delivery to various clients (for example, TV, PC, and mobile devices).

    Setting Up Media Services

    To get started, search for Media Services by typing it in the search box and then click on the first one under Web + Mobile category

    When you click on the Create button, you will be prompted to give a Name, choose a subscription, resource group, location and a storage account. Make sure that you choose the same region for your location and storage account, otherwise you may face problems down the line.

    We are now all set for creating a media service, just click on the Create button to start the deployment and you will see a new entry under Media Services after the deployment as shown below.

  • Executing a Task in the Background in ASP.NET MVC

    In some cases we want to execute some long running task in the background without affecting the main thread. One classic example is sending mails when we are implementing a sign in module. Mostly people will either go for a scheduled job independent of the application or do it in the main thread itself. 

    .NET Framework 4.5.2 has got a new API called QueueBackgroundWorkItem which can execute short-lived resource intense tasks in an effective and reliable manner. As per the documentation

    QBWI schedules a task which can run in the background, independent of any request. This differs from a normal ThreadPool work item in that ASP.NET automatically keeps track of how many work items registered through this API are currently running, and the ASP.NET runtime will try to delay AppDomain shutdown until these work items have finished executing.

    One of the advantages of using the QBWI(QueueBackgroundWorkItem) is that it can keep track of the items that are registered through this API is currently running and the runtime will be able to delay the shutdown of the App Domain upto 90 seconds so that the running tasks can be completed. 

    Let's see an example of file upload in ASP.NET MVC. In this example, I will chose file from the local machine using the file upload control and when you click the Upload button, the file will be saved inside a folder in the server which will be handled by the QBWI. 

    View 

    @{
        ViewBag.Title = "Index";
    }
    @model List<string>
    
    <h2>Index</h2>
    @using (Html.BeginForm("UploadFile", "Home", FormMethod.Post, new { id = "frmImageGallery", enctype = "multipart/form-data" }))
     { 
       <input type="file" name="file" />
       <input type="submit" value="Upload"  id="btnUpload" />
     }
    
    <h2>Images</h2>
    @foreach (var item in Model)
    { 
        <p><img src="@String.Concat("Images/Uploaded/",item)" style="height:200px" /></p><br />
    }
    <script>
        $(function () {
            $(document).on("click", "#btnUpload", function (event) {
                event.preventDefault();
                var fileOptions = {
                    success: res,
                    dataType: "json"
                }
                $("#frmImageGallery").ajaxSubmit(fileOptions);
            });
    
        }); 
    </script>
    
    

    Categories: C#, Web Developement, MVC

  • Add/Remove References Using dotnet CLI Tool

    In the latest update made to the .NET Core tooling, dotnet new and add command has undergone significant changes in the usage and options available for the command. You can read more about the updates here in the official blog. In this current update it replaces the dotnet add p2p command with a new syntax.

    Adding a Reference

    Syntax

    dotnet add reference <path to project file>

    Usage 

    dotnet add reference ..\Lib\Lib.csproj

    When you execute the following command it will get added to the project and if look at the csproj file of the project to which the reference is added you will see the entry for it

    Remove a Reference

    Syntax

    dotnet remove reference <path to the proj file which needs to be removed>

    Usage

    dotnet remove reference ..\Lib\Lib.csproj

    To remove the referernce we will use the dotnet remove reference as shown below.

    Categories: C#, DotNet CLI

  • 1
  • 2
  • 3
  • ...