Getting Started With ASP.NET CORE 1.0

Introduction
 
In this article, I will explain how to install .NET Core tools preview for Visual Studio and how to print “Hello World” in the latest ASP.NET Core 1.0.
 
Step 1
 
First download Visual Studio 2015 with Update 3 through the link click here.
 
Step 2
 
Go to Install .NET Core tools preview for Visual Studio. This .NET Core tools adds support for .NET Core projects in Visual Studio 2015.

Install DotNet Core
Step 3
 
This is really interesting. Open Visual Studio 2015 and create new Project.

Open Templates – > Visual C# -> Click .NET Core Category and you can see “ASP.NET Core Web Application” template.

DotnetCore Template in VS 2015

Step 4 
 
Select Empty Templates ( based on your requirement ) in ASP.NET Core Templates Category if you are going to host the app in Microsoft Azure Service and check in the “Host in the cloud option”.

DotNet Core Empty Page

Step 5
 
Open “Startup.cs” class in “HelloWorldDotnetCore” project folder. 



Step 6
 
We are creating mini middle ware Application, using lambda expression in “app.Run”. This piece of code is creating “Hello World”. 
 
C# Code
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Threading.Tasks;  
  5. using Microsoft.AspNetCore.Builder;  
  6. using Microsoft.AspNetCore.Hosting;  
  7. using Microsoft.AspNetCore.Http;  
  8. using Microsoft.Extensions.DependencyInjection;  
  9. using Microsoft.Extensions.Logging;  
  10.   
  11. namespace HelloWorldDotnetCore  
  12. {  
  13.     public class Startup  
  14.     {  
  15.         // This method gets called by the runtime. Use this method to add services to the container.  
  16.         // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940  
  17.         public void ConfigureServices(IServiceCollection services)  
  18.         {  
  19.         }  
  20.   
  21.         // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.  
  22.         public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)  
  23.         {  
  24.             loggerFactory.AddConsole();  
  25.   
  26.             if (env.IsDevelopment())  
  27.             {  
  28.                 app.UseDeveloperExceptionPage();  
  29.             }  
  30.            app.Run(async (context) =>  
  31.             {  
  32.                 await context.Response.WriteAsync(" Hello World! ");  
  33.             });  
  34.              
  35.         }  
  36.     }  
  37. }  
Output 1
 
 
Step 7
 
“app.run” doesn’t work in .NET Core followed by using “app.Use”. It will pass two parameters and add the next middleware content In .NET Core. 
 
C# Code
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Threading.Tasks;  
  5. using Microsoft.AspNetCore.Builder;  
  6. using Microsoft.AspNetCore.Hosting;  
  7. using Microsoft.AspNetCore.Http;  
  8. using Microsoft.Extensions.DependencyInjection;  
  9. using Microsoft.Extensions.Logging;  
  10.   
  11. namespace HelloWorldDotnetCore  
  12. {  
  13.     public class Startup  
  14.     {  
  15.         // This method gets called by the runtime. Use this method to add services to the container.  
  16.         // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940  
  17.         public void ConfigureServices(IServiceCollection services)  
  18.         {  
  19.         }  
  20.   
  21.         // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.  
  22.         public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)  
  23.         {  
  24.             loggerFactory.AddConsole();  
  25.   
  26.             if (env.IsDevelopment())  
  27.             {  
  28.                 app.UseDeveloperExceptionPage();  
  29.             }  
  30.             app.Use(async (context, next) =>  
  31.             {  
  32.                 await context.Response.WriteAsync("Hello World!!");  
  33.                 await next();  
  34.             });  
  35.   
  36.             app.Run(async (context) =>  
  37.             {  
  38.                 await context.Response.WriteAsync(" Welcome to Dotnet Core ");  
  39.             });  
  40.              
  41.         }  
  42.     }  
  43. }  
Output 2
 
 
Reference
Conclusion
 
We learned how to Install .NET Core tools preview for Visual Studio and how to print “Hello World” in the latest ASP.NET Core 1.0.

Up Next
    Ebook Download
    View all
    Learn
    View all