ASP.NET Core PART-1

In this post we are going to explore ASP.NET as open source web framework. First of all we will differentiate between .NET Framework(ASP.NET 4.6) & .NET Core(ASP.NET 5.0).

After that we will get basic overview ASP.NET Core 1.0 with creating a sample application.

 let’s get started:

 core_0

From above figure we can see that ASP.Net has two variation, one is .Net Framework which is now updated to version 4.6 or later by which we can create ASP.Net Web Form, MVC, Web API applications & another one is newly created open source WEB Framework(.Net Core) that can run & develop on cross platform (Windows, Linus, Mac).

If notice that .NET Core also has two variation that we can develop & run applications by targeting .NET Core 1.0 or .NET Framework, But .NET Core 1.0 doesn’t have all the features of .NET Framework.

Let’s differentiate both.

.Net Framework:

  • Developed and run on Windows Platform only.
  • Built on the .NET Framework runtime.
  • Supported (MVC, Web API & SignalR) Dependency Injection (DI).
  • MVC & Web Api Controller are separated.

 

.Net Core:

  • Open Source.
  • Developed and run on Cross Platform.
  • Built on the .NET Core runtime & also on .NET Framework.
  • Facility of dynamic compilation.
  • Built in Dependency Injection (DI).
  • MVC & Web Api Controller are unified, Inherited from same base class.
  • Smart tooling like(Bower, Grunt & Gulp).
  • Command-line tools.

 

Get started with .NET Core:  We will now get described how we can enabled .NET Core on our development PC.

We need to install Visual Studio 2015 & .NET Core . I have installed Visual Studio 2015 Update 3* & for Windows.

Let’s create a new project with Visual Studio 2015 > File > New > Project

core_2

Click OK & choose a template in this case we are going to select an empty ASP.NET Core Template.

core_3

Finally we can see the welcome screen of sample app.

core_33

In Output tab we can see the package restored successfully. Let’s explore the app solution folder.

In Solution explorer there two main folder one is Solution Items & another one is SRC

core_6

In Solution Items there is a file named global.json which contained below code snippet which is actually settings of whole solution.

{
  "projects": [ "src", "test" ],
  "sdk": {
    "version": "1.0.0-preview2-003121"
  }
}

Code Explanation:

“projects”: [ “src”, “test” ] – is array type which specifies a list of project folder that are included in this solution.

"sdk": {
    "version": "1.0.0-preview2-003121"
  }

Specifies SDK information along with SDK version, this has also specify another two properties – architecture & runtime.

"version": {
          "type": "string",
          "description": "The version of the SDK to use."
        },
"architecture": {
          "enum": [ "x64", "x86" ],
          "description": "Specify which processor architecture to target."
        },
"runtime": {
          "enum": [ "clr", "coreclr" ],
          "description": "Chose which runtime to target."
        }

Final Code Snippet after edit.

{
  "projects": [ "src", "test" ],
  "sdk": {
    "version": "1.0.0-preview2-003121",
    "architecture": "x64",
    "runtime": "coreclr"
  }
}

Runtime specifies as CLR = ASP.NET 4.6 runtime & as CORECLR = ASP.NET Core 1.0 runtime.

Let’s get explained about Project.json

 core_7

“dependencies”: It define which dependency package are required to run the application.

core_9

Additional properties are:

  1. Version
  2. Type
  3. Target
  4. Include
  5. Exclude
  6. suppressParent

 

“frameworks”: Defines target frameworks that will be built.

core_11

“buildOptions”: Define options that are passed to the compiler.

core_12

“runtimeOptions”: Manage server garbage collection at application runtime. The properties are:

  1. GC.Server
  2. GC.Concurrent

 

“publishOptions”: This define the file/folder to include/exclude to/from the output folder while publish the application.

core_10

“scripts”: Scripts is object type which specifies that scripts to run during build or publish the application.

core_8

 

Program.cs

In program class main method use WebHostBuilder to create web application host.

core_19

.UseKestrel() : Define the web server. ASP.NET Core supports hosting in IIS and IIS Express, and self-hosting scenarios using the Kestrel and WebListener HTTP servers.

Two different HTTP servers:

  1. AspNetCore.Server.Kestrel (AKA Kestrel, cross-platform)
  2. AspNetCore.Server.WebListener (AKA WebListener, Windows-only, preview)

 

.UseContentRoot(Directory.GetCurrentDirectory()) : Application base path that specifying path to root directory of the application.

The web root path defaults to /wwwroot, but you can specify a different location using the WebHostBuilder.

.UseIISIntegration() : For hosting in IIS and IIS Express.

.UseStartup() : Specifies the Startup class.

core_20

.Build() : The Build and Run methods build the IWebHost that will host the app and start it listening for incoming HTTP requests.

core_21

.Run() :

core_22

That’s all for now, next part we will focus on ASP.Net MVC & Client Side Dependencies.

Hope this will help 🙂

Author:

Since March 2011, have 8+ years of professional experience on software development, currently working as Senior Software Engineer at s3 Innovate Pte Ltd.

5 thoughts on “ASP.NET Core PART-1”

Leave a Reply