Header add


.NET Core is a free, open-source framework for building modern, scalable, and high-performance cross-platform software applications.

.NET Core is the most versatile framework and can be used to build all kinds of software including Web applications, Mobile apps, Desktop applications, Cloud services, Microservices, APIs, Games, and IoT applications. Unlike other frameworks, .NET Core is not limited to a single programming language and supports C#, VB.NET, F#, XAML, and TypeScript. These programming languages are open source and managed by independent communities.

Let's Create a new "Hello World" application and see how the .Net core application work in Visual studio.
Step 1: Visual Studio 2017–>File->New–>Project
  • Choose C# as language and ASP .Net Core Web application. 
  • Also choose the folder path where want to save your project.
  • The project name is set as "HelloWorld" and then click "OK"
Choose ASP .NET Core application

Step 2:  Select the empty template as like below:
  • Choose ASP .Net Core 2.2
  • Unchecked the Configure HTTPS button as we want to run the application in HTTP only, if you want to run it on HTTPS then you can select the checkbox (But application running in HTTPS need to ). We should configure HTTPS instead of HTTP we should discuss it in later article.
Step 3: Folder structure of ASP .Net Core


  • You can see there is showing "appsettings.json" through you can configure your project settings. 
  • When the project will run it first hit the "Programm.cs" file and it navigate it into "Startup.cs" file.
  • Please follow the link to see the Folder Structure of .NET Core MVC
Step 4: Program.cs : It is the main entry point for the application like console application in .NET framework. It then goes to the Startup.cs class to finalize the configuration of the application.
     using System;  
     using System.Collections.Generic;  
     using System.IO;  
     using System.Linq;  
     using System.Threading.Tasks;  
     using Microsoft.AspNetCore;  
     using Microsoft.AspNetCore.Hosting;  
     using Microsoft.Extensions.Configuration;  
     using Microsoft.Extensions.Logging;  
     namespace HelloWorld  
     {  
       public class Program  
       {  
         public static void Main(string[] args)  
         {  
           CreateWebHostBuilder(args).Build().Run();  
         }  
         public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>  
           WebHost.CreateDefaultBuilder(args)  
             .UseStartup<Startup>();  
       }  
     }  

Step 5 - Startup.cs : It includes Configure and Configure Services methods.
      using System;   
      using System.Collections.Generic;   
      using System.Linq;   
      using System.Threading.Tasks;   
      using Microsoft.AspNetCore.Builder;   
      using Microsoft.AspNetCore.Hosting;   
      using Microsoft.AspNetCore.Http;   
      using Microsoft.Extensions.DependencyInjection;   
      namespace HelloWorld   
      {   
       public class Startup   
       {   
        // This method gets called by the runtime. Use this method to add services to the container.   
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940   
        public void ConfigureServices(IServiceCollection services)   
        {   
        }   
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.   
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)   
        {   
         if (env.IsDevelopment())   
         {   
          app.UseDeveloperExceptionPage();   
         }   
         app.Run(async (context) =>   
         {   
          await context.Response.WriteAsync("Hello World!");   
         });   
        }   
       }   
      }   
  • "env.IsDevelopment" refers that the project run in development mode, you can change it into Production, staging mode accordingly.
Step 6: Now run the application with VS start button or F5 and see the result.


 Summary
In this tutorial we discussed "Hello world" Program in .NET Core MVC Web application. Stay tuned for more interesting topic about .NET Core application.

Post a Comment

Previous Post Next Post