In this article, we will learn the top 10 new features of ASP.net Core.

1. Cross Platform Support:



Earlier NET framework was targeted towards the Windows platform. But, ASP.NET Core is a new modular framework developed to support multiple platforms including Windows, Mac, and Linux. Also, ASP.NET web applications, primarily run under IIS, but the ASP.NET Core applications can run under non-IIS Web servers.



2. Open Source:



Asp.net source code and documentations, both are now open source. The source code is available in github and you can download/change any code that you like. If any build works, you can raise a pull request for microsoft to consider it and merge it.Similarly, all documents are also open source and available in docs.asp.net.Each article has an “edit this page” option on top and you can edit the documents and submit it to microsoft for approval.Asp.net core is open source but Microsoft will still provide support for 3 years to each major/minor release.



3. Project.json:



Asp.net Core uses Project.JSON file for storing all project level configuration settings.The Project.json file stores configuration information in JSON format.



{ "dependencies": { "Microsoft.NETCore.App": { "version": "1.0.0", "type": "platform" }, "Microsoft.ApplicationInsights.AspNetCore": "1.0.0", "Microsoft.AspNetCore.Diagnostics": "1.0.0", "Microsoft.AspNetCore.Mvc": "1.0.0", "Microsoft.AspNetCore.Razor.Tools": { "version": "1.0.0-preview2-final", "type": "build" }, "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0", "Microsoft.AspNetCore.Server.Kestrel": "1.0.0", "Microsoft.AspNetCore.StaticFiles": "1.0.0", "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0", "Microsoft.Extensions.Configuration.Json": "1.0.0", "Microsoft.Extensions.Logging": "1.0.0", "Microsoft.Extensions.Logging.Console": "1.0.0", "Microsoft.Extensions.Logging.Debug": "1.0.0", "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0", "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0" }, "tools": { "BundlerMinifier.Core": "2.0.238", "Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final", "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final" }, "frameworks": { "netcoreapp1.0": { "imports": [ "dotnet5.6", "portable-net45+win8" ] } }, "buildOptions": { "emitEntryPoint": true, "preserveCompilationContext": true }, "runtimeOptions": { "configProperties": { "System.GC.Server": true } }, "publishOptions": { "include": [ "wwwroot", "Views", "Areas/**/Views", "appsettings.json", "web.config" ] }, "scripts": { "prepublish": [ "bower install", "dotnet bundle" ], "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ] } } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 { "dependencies" : { "Microsoft.NETCore.App" : { "version" : "1.0.0" , "type" : "platform" } , "Microsoft.ApplicationInsights.AspNetCore" : "1.0.0" , "Microsoft.AspNetCore.Diagnostics" : "1.0.0" , "Microsoft.AspNetCore.Mvc" : "1.0.0" , "Microsoft.AspNetCore.Razor.Tools" : { "version" : "1.0.0-preview2-final" , "type" : "build" } , "Microsoft.AspNetCore.Server.IISIntegration" : "1.0.0" , "Microsoft.AspNetCore.Server.Kestrel" : "1.0.0" , "Microsoft.AspNetCore.StaticFiles" : "1.0.0" , "Microsoft.Extensions.Configuration.EnvironmentVariables" : "1.0.0" , "Microsoft.Extensions.Configuration.Json" : "1.0.0" , "Microsoft.Extensions.Logging" : "1.0.0" , "Microsoft.Extensions.Logging.Console" : "1.0.0" , "Microsoft.Extensions.Logging.Debug" : "1.0.0" , "Microsoft.Extensions.Options.ConfigurationExtensions" : "1.0.0" , "Microsoft.VisualStudio.Web.BrowserLink.Loader" : "14.0.0" } , "tools" : { "BundlerMinifier.Core" : "2.0.238" , "Microsoft.AspNetCore.Razor.Tools" : "1.0.0-preview2-final" , "Microsoft.AspNetCore.Server.IISIntegration.Tools" : "1.0.0-preview2-final" } , "frameworks" : { "netcoreapp1.0" : { "imports" : [ "dotnet5.6" , "portable-net45+win8" ] } } , "buildOptions" : { "emitEntryPoint" : true , "preserveCompilationContext" : true } , "runtimeOptions" : { "configProperties" : { "System.GC.Server" : true } } , "publishOptions" : { "include" : [ "wwwroot" , "Views" , "Areas/**/Views" , "appsettings.json" , "web.config" ] } , "scripts" : { "prepublish" : [ "bower install" , "dotnet bundle" ] , "postpublish" : [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ] } }



Please Note, Microsoft has decided to move .NET Core projects to .csproj/MSBuild so all .NET projects will use the same tooling and build system. Starting in .NET Core RTM/tooling preview 2, Visual Studio will automatically rename .xproj files as .csproj.



4. Appsettings.json:



ASP.NET stores application configuration settings in Web.config.ASP.NET Core uses AppSettings.json to store custom application setting, DB connection strings,Logging etc.. Below is a sample of Appsettings.json:



{ "ApplicationInsights": { "InstrumentationKey": "" }, "Logging": { "IncludeScopes": false, "LogLevel": { "Default": "Debug", "System": "Information", "Microsoft": "Information" } } } 1 2 3 4 5 6 7 8 9 10 11 12 13 { "ApplicationInsights" : { "InstrumentationKey" : "" } , "Logging" : { "IncludeScopes" : false , "LogLevel" : { "Default" : "Debug" , "System" : "Information" , "Microsoft" : "Information" } } }

5. Startup.cs:



In ASP.NET, Global.asax acts as the entry point for your application.In ASP.net Core,startup.cs is the entry point for your application.



public class Startup { public Startup(IHostingEnvironment env) { var builder = new ConfigurationBuilder() .SetBasePath(env.ContentRootPath) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true) .AddEnvironmentVariables(); if (env.IsDevelopment()) { // This will push telemetry data through Application Insights pipeline faster, allowing you to view results immediately. builder.AddApplicationInsightsSettings(developerMode: true); } Configuration = builder.Build(); } public IConfigurationRoot Configuration { get; } // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { // Add framework services. services.AddApplicationInsightsTelemetry(Configuration); services.AddMvc(); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); app.UseApplicationInsightsRequestTelemetry(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseBrowserLink(); } else { app.UseExceptionHandler("/Home/Error"); } app.UseApplicationInsightsExceptionTelemetry(); app.UseStaticFiles(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); } } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 public class Startup { public Startup ( IHostingEnvironment env ) { var builder = new ConfigurationBuilder ( ) . SetBasePath ( env . ContentRootPath ) . AddJsonFile ( "appsettings.json" , optional : true , reloadOnChange : true ) . AddJsonFile ( $ "appsettings.{env.EnvironmentName}.json" , optional : true ) . AddEnvironmentVariables ( ) ; if ( env . IsDevelopment ( ) ) { // This will push telemetry data through Application Insights pipeline faster, allowing you to view results immediately. builder . AddApplicationInsightsSettings ( developerMode : true ) ; } Configuration = builder . Build ( ) ; } public IConfigurationRoot Configuration { get ; } // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices ( IServiceCollection services ) { // Add framework services. services . AddApplicationInsightsTelemetry ( Configuration ) ; services . AddMvc ( ) ; } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure ( IApplicationBuilder app , IHostingEnvironment env , ILoggerFactory loggerFactory ) { loggerFactory . AddConsole ( Configuration . GetSection ( "Logging" ) ) ; loggerFactory . AddDebug ( ) ; app . UseApplicationInsightsRequestTelemetry ( ) ; if ( env . IsDevelopment ( ) ) { app . UseDeveloperExceptionPage ( ) ; app . UseBrowserLink ( ) ; } else { app . UseExceptionHandler ( "/Home/Error" ) ; } app . UseApplicationInsightsExceptionTelemetry ( ) ; app . UseStaticFiles ( ) ; app . UseMvc ( routes = > { routes . MapRoute ( name : "default" , template : "{controller=Home}/{action=Index}/{id?}" ) ; } ) ; } }

In Startup.cs file,

– The constructor loads the AppSettings.json file using ConfigurationBuilder class.

– The ConfigureServices() method adds the services required by the application. For example, here you add MVC and Entity Framework to the services collection.

– The Configure() method specifies and configures the services added earlier for application’s use.



6. Grunt, Gulp and Bower:



Gulp and Grunt are JavaScript task runners. They help you automate commonly needed tasks, such as bundling JavaScript and CSS files, minifying JavaScript and CSS files. You can install Grunt and Gulp usingNode Project Manager(NPM). In Asp.net Core, the ASP.NET Core project created using Visual Studio 2015 allows you to add Grunt and Gulp configuration files and also provides Task Runner Explorer to monitor the tasks





Bower is a “package manager for the web.” Bower lets you install and restore client-side packages, including JavaScript and CSS libraries.

For example, with Bower you can install CSS files, fonts, client frameworks, and JavaScript libraries from external sources. Bower resolves dependencies and will automatically download and install all the packages you need. For example, if you configure Bower to load the Bootstrap package, the necessary jQuery package will automatically come along for the ride.Read more on Bower with ASP.net Core



7. Dependency Injection:



The Dependency Injection helps us to develop loosely couple code by ensuring that high-level modules depend on abstractions rather than concrete implementations of lower-level modules.ASP.NET Core provides an inbuilt dependency injection framework.The ConfigureServices method in the Startup class is responsible for defining the services the application will use, including platform features like Entity Framework Core and ASP.NET Core MVC.

8. Single Programming model for MVC and Web API:



In MVC 5, controllers inherit from the System.Web.Mvc.Controller base class. And, Web API 2 controllers inherit from System.Web.Http.ApiController. In ASP.NET Core, both of these frameworks are merged into a single framework. So, under ASP.NET Core, an MVC controller and Web API controller both inherit from Microsoft.AspNet.Mvc.Controller base class. Then can configure HTTP verbs mapping and the routing of the controllers as required.

9. wwwroot folder and Static files:



In ASP.NET, there are no fixed location for storing static files such as image files, JavaScript files, and CSS files.But,in ASP.NET Core, all the static files are kept under the wwwroot folder (default). You also can change the name of this folder by using the Project.json file.





10. MVC Tag Helpers:



With ASP.NET Core, Microsoft has introduced tage helpers to generate client-side code from .NET and make it easier to re-use in Razor markup.They are referenced in your server-side markup as though they were another HTML tag that you were using. The Razor engine will recognize the tag and execute the relevant .NET Code that corresponds to it.

You can read more on new features of ASP.net core here.

Summary:

In this article, we have discussed:

– Appsettings.json in ASP.net core

– Bower in ASP.net Core

– Cross platform support on ASP.net Core

– Dependency Injection in ASP.net Core

– Grunt,Gulp and Browser support in ASP.net Core

– MVC Tag Helpwer in ASP.net Core

– Project.json in ASP.net Core

– Startup.cs in ASP.net Core

– wwwroot and Static files in ASP.net Core

Thanks for visiting !!

© 2016, Csharp Star. All rights reserved.