ASP.NET Core 1.0

In this opportunity I will be writing about one of the most used (and newest) and functional server-side web application framework: ASP.NET Core. Before entering into the ecosystem of this tool allow me to give you some feedback that may be needed in order to have a better understanding of topics related with versions, features and releases (this one is quite new).

Asp.net core

What is ASP.NET Core 1.0?

ASP.NET Core 1.0 is, in short terms, the evolution of ASP.NET 4.6. If you are thinking that it is just a superior version of ASP.NET 4.6 take away that myth of your head because ASP.NET Core 1.0 is an entire new based-cloud applications framework written from scratch, with a new focus different from its predecessor.
Two of the most appreciated characteristics of this new framework are:
First it is open source (supported by Microsoft) meaning that you can find and download the code on GitHub , also contribute to the development of it, and second, it is cross-platform, so you can run it either in Windows, Linux or Mac OS.

Advantages and Disadvantages. Looking back to ASP.NET 5.

Good:

– Open source: as I mentioned before, this is a huge advantage and everybody loves it.
– Cross-platform: this is an obvious point, run it everywhere!.
– Modular design: the main stuff here is NuGet packages. Developers can use NuGet Package Manager to install libraries to extend the features of apps so now is easier to maintain the code due to the benefits of package-based software.
– MVC and WEB.API are together in one: Back in ASP.NET, MVC and WEB.API were based on different versions of the framework and because of this some differences related to namespace and classes were present and tend to confuse sometimes. Now arrives MVC 6, a unique collection of objects with a unique namespace (Microsoft.AspNet.Mvc), this standard simplifies the development process.
– Dependency injection: Before this was available as an ad-on but now it is built-in the framework, but still third party’s solutions like Autofac should be functional.
– Productivity: The keyword here is Kestrel, a lightweight web server incorporated by Microsoft as an alternative to developer’s who does not want to use heavy options to host development. With Kestrel you can run the site in OSX.
– Easier integration with client-side frameworks like AngularJS, KnockoutJS and Bootstrap.

Bad:

– Issues with documentation in certain way: When in May of 2016 the RC2 of ASP.NET Core 1.0 was released the documentation was ‘incompleted’ because a lot of topics were without text. Today this situation was patched but sometimes you can find some cases, take in count that ASP.NET Core 1.1 is out too. God bless StackOverflow! 😉
– Sometimes when you are searching for information maybe a little bit hard, because this framework had many names in the past, first vNext, next ASP.NET 5 and today ASP.NET Core, this is not helpful.
– Compatibles solutions between versions not always is the best. You can find a solution to a specific trouble but it may not work because maybe it was written to a previous version. Thanks to GitHub and open source this can be fixed eventually because there is always an alternative.

What about ASP.NET Core 1.1?

The .NET Core 1.0 was updated with some changes, you can see them all here in the release notes.

Some of them are:
– Improved middleware in all sense through the user interface.
– Improved deployment of ASP.NET core apps on Microsoft Azure, increased the cloud support.
– Now other hosting options are available, beside IIS.

Let’s see an example of code, in this case it going to be an URL Rewriting Middle ware: (this was taken from here, check it if you want to see more examples.)

“URL Rewriting allows mapping a public URL space, designed for consumption of your clients, to whatever representation the downstream components of your middleware pipeline require as well as redirecting clients to different URLs based on a pattern.”

 
using System.IO;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Rewrite;
namespace MyApplication {

public class Startup {

public void Configure(IApplicationBuilder app, IHostingEnvironment env) 
{

var options = new RewriteOptions()
.AddRedirect("(.*)/$", "$1") // Redirect using a regular expression
.AddRewrite(@"app/(\d+)", "app?id=$1", skipRemainingRules: false) // Rewrite based on a Regular expression
.AddRedirectToHttps(302, 5001) // Redirect to a different port and use HTTPS
.AddIISUrlRewrite(env.ContentRootFileProvider, "UrlRewrite.xml") // Use IIS UrlRewriter rules to configure
.AddApacheModRewrite(env.ContentRootFileProvider, "Rewrite.txt"); // Use Apache mod_rewrite rules to configure
app.UseRewriter(options);
}

// More Code

}

}

From .Net Framework 4.6 to .Net Core 1.0 :

asp.net core chart

This images illustrates the main changes with its predecessor. I recommend you to read this post to understand some considerations before migrating from .NET 4.6 to .NET Core 1.0 as well as strategies and advices from the author to achieve it. In case you are not sure about what solution suits you, and need to pick, this post can give you a clear understanding.

Other resources to learn more about ASP.NET Core

Tutorials

Microsoft Virtual Academy – Introduction to ASP.NET Core

Building your first ASP.NET Core MVC application

Building Your First Web API with ASP.NET Core MVC and Visual Studio


 
 
 

Leave a Reply

Your email address will not be published. Required fields are marked *