Top 13 ASP.NET Core Features You Need to Know

Top 13 ASP.NET Core Features You Need to Know
Top 13 ASP.NET Core Features You Need to Know

ASP.NET is one of the most profitable net software improvement frameworks by using Microsoft. With each and every update, new and prolonged aspects are introduced that assist builders install notably scalable and high-performance net applications.

When coupled with utility monitoring and different overall performance tools, such as a profiler, ASP.NET turns into a effective answer for constructing splendid apps.

Within the framework itself, there are myriad points to assist you overcome frequent improvement challenges, do greater with your apps, and enhance performance.

1. Cross-platform & container support

With the introduction of .NET Core, you can now create ASP.NET functions and set up them to Windows, Linux, and macOS. Microsoft and the neighborhood have put a large effort into making Linux a excellent citizen for jogging ASP.NET.

Containers are consuming the clouds these days. Docker, Kuberenetes and different applied sciences are all the rage. ASP.NET Core approves builders to make use of all of these new technologies. Microsoft Azure even has help for deploying your software to containers and Kubernetes.

2. High performance

Some say that overall performance is a integral characteristic of your software. I have a tendency to agree! With the introduction of ASP.NET Core and the Kestrel internet server, ASP.NET is touted as one of the quickest internet utility frameworks available. TechEmpower has some cool benchmarks you can take a look at out.

The technological know-how that powered the ASP.NET built-in pipeline and IIS was once roughly 15 years old. It did the whole thing and carried a lot of baggage with it. The new Kestrel internet server used to be redesigned from the floor up to take benefit of asynchronous programming models, be tons extra lightweight, and fast!

3. Asynchronous via async/await

ASP.NET has exceptional aid for making use of asynchronous programming patterns. Async is now carried out in all frequent .NET Framework lessons and most third-party libraries. Most cutting-edge functions spend most of their time and CPU cycles ready for database queries, net provider calls, and different I/O operations to complete.

One of the motives ASP.NET Core is quicker is its large use of asynchronous patterns inside the new MVC and Kestrel frameworks.

//mark the method as async
public async Task GetGWB()
{
    HttpClient hc = new HttpClient();
    //await keyword handles all the complexity of async threading and callbacks
    await hc.GetAsync("http://geekswithblogs.net/Default.aspx");
    return true;
}

4. Unified MVC & Web API frameworks

Before ASP.NET Core, builders have been most normally the usage of the MVC and Web API frameworks. MVC used to be tailor-made to growing net purposes that served up HTML. Web API was once designed to create RESTful offerings the usage of JSON or XML.

With ASP.NET Core, MVC and Web API have been merged together. There used to be constantly a lot of overlap with the two frameworks. MVC should usually return JSON information rather of HTML. Combining them was once a proper go and simplifies development.

Learn more: Goodbye Web API: Your Guide to RESTful APIs with ASP.NET Core

With ASP.NET Core we additionally have the new Razor Pages. They lengthen the MVC framework to enable encapsulating the controller and mannequin components of a web page collectively with two-way binding. They are type of a substitute for WebForms whilst the usage of the acquainted Razor syntax.

5. Multiple environments and development mode

One of my favored points is the new surroundings feature. It lets in you to without difficulty differentiate components of your code for their conduct in development, staging, production, etc. There was once no trendy way to do this earlier than ASP.NET Core.

For example, it is used inside your Startup.cs file to assist configure your application. In this case, whether or not or now not we desire to exhibit a extra distinctive exception web page for improvement only.

Environments are ideal for the usage of exclusive CSS or Javascript files. Use your CDN in production, however nearby documents at some stage in development. This is a snippet out of my Razor sketch view.

<environment names="Development">
        <script src="~/lib/jquery/dist/jquery.js"></script>
        <script src="~/lib/bootstrap/dist/js/bootstrap.js"></script>
        <script src="~/js/site.js" asp-append-version="true"></script>
    </environment>
    <environment names="Staging,Production">
        <script src="https://ajax.aspnetcdn.com/ajax/jquery/jquery-2.2.0.min.js"
                asp-fallback-src="~/lib/jquery/dist/jquery.min.js"
                asp-fallback-test="window.jQuery"
                crossorigin="anonymous"
                integrity="sha384-K+ctZQ+LL8q6tP7I94W+qzQsfRV2a+AfHIi9k8z8l9ggpc8X+Ytst4yBo/hH+8Fk">
        </script>
        <script src="https://ajax.aspnetcdn.com/ajax/bootstrap/3.3.7/bootstrap.min.js"
                asp-fallback-src="~/lib/bootstrap/dist/js/bootstrap.min.js"
                asp-fallback-test="window.jQuery && window.jQuery.fn && window.jQuery.fn.modal"
                crossorigin="anonymous"
                integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa">
        </script>
        <script src="~/js/site.min.js" asp-append-version="true"></script>
    </environment>  

6. Dependency Injection

One of the top notch new facets of ASP.NET Core is constructed in dependency injection. It is closely used inside ASP.NET MVC itself. It is the desired way that matters like logging contexts, database contexts, and different matters are handed into your MVC controllers.

public class PaymentService: IPaymentService
{
  public ILogger Logger { get; }

  //automatically passes the logger factory in to the constructor via dependency injection
  public PaymentService(ILoggerFactory loggerFactory)
  {
    Logger = loggerFactory?.CreateLogger();
    if(Logger == null)
    {
      throw new ArgumentNullException(nameof(loggerFactory));
    }
    Logger.LogInformation("PaymentService created");
  }
}

7. WebSockets & SignalR

ASP.NET has first type assist for WebSockets. This can be used to persist lengthy strolling connections and talk again and forth with the browser. SignalR is a full framework that is additionally reachable that makes it effortless deal with frequent scenarios.

We use SignalR very closely. For example, when viewing the present day monitoring statistics about one of your servers, each time we get hold of new data, we right now push it to your browser so you can see it replace in actual time. These sorts of eventualities are ideal for WebSockets and SignalR makes it convenient to do.

Note: At the time of this article, SignalR is still in beta for ASP.NET Core. 

8. Cross-Site Request Forgery (CSRF) Protection

Security is important. It is additionally one of these matters that can be a lot of work to forestall positive sorts of attacks. CSRF is in referencing to hijacking customers authenticated session to function an motion that they did now not initiate.

For example, let’s fake that you log in to your financial institution account and then navigate to a one-of-a-kind website. If that different internet site ought to do a POST to your financial institution internet site to switch funds, that would be a terrible thing. It may want to doubtlessly do that if your on-line session on the banking internet site is legitimate and the financial institution does no longer proper validate requests.

ASP.NET has a top framework that is on hand to stop these sorts of attacks. It generates anti-forgery tokens.

Learn more: XSRF/CSRF Prevention in ASP.NET MVC and Web Pages

9. “Self hosted” Web Applications

Sometimes you want to make a internet utility that will be deployed on to a computing device and now not a server jogging IIS. Our free ASP.NET profiler, Prefix, is a ideal instance of this. Its the front cease is all HTML that is loaded from an ASP.NET utility going for walks as a Windows Service.

You can create a self-hosted ASP.NET internet software countless exclusive ways. In .NET 4.5 you ought to accomplish it via the use of Owin, Nancy, or WCF. For Prefix, we use ASP.NET Web API with Owin.

With ASP.NET Core, you can additionally use the general Kestrel net server. One of the splendid blessings of .NET Core is that your internet software is in reality a console application. IIS simply sits in the front of it as a reverse proxy. This capacity that you can additionally install your app solely with kestrel for non-server primarily based use cases, like Prefix.

10. Action Filters

One of the gorgeous elements of ASP.NET is the aid for extensible filters. This lets in you to put in force performance that can be utilized to an whole controller or motion barring enhancing the motion itself.

Filters are used to specify caching, error handling, authorization, or any customized common sense you would like to implement.

using System;
using System.Web.Mvc;

namespace MvcApplication1.Controllers
{
     public class DataController : Controller
     {
          [OutputCache(Duration=10)]
          public string Index()
          {
               return DateTime.Now.ToString("T");
          }
     }
}

Learn more: Understanding Action Filters

11. Extensible Output Caching

This characteristic approves ASP.NET to cache the output generated by means of a web page and serve this cached content material for future requests. It shops the information that is now not up to date regularly and outputs that unique records from a cached location.

ASP.NET makes it handy to specify how lengthy any request need to be cached through frequent HTTP headers. It additionally has guide for caching output inside the reminiscence on your internet server itself. You can even use Redis or different carriers to manage your output caching.

12. Globalization and Localization

ASP.NET makes it convenient to localize dates, numbers, and the textual content inside your internet application. If you favor your utility to be used throughout the globe, localization will be very necessary to you.

ASP.NET permits customizing your utility for more than one languages by way of aid files. These aid documents are viewed as the central repository the place all texts are kept, and internet pages can examine this useful resource file and get labels populated. There are two kinds of resources:

  • Local Resources – unique for a web page (i.e., there will be nearby aid file for each page)
  • Global Resources – frequent for the total internet site (i.e., one aid file accessed by way of all pages)

13. Swagger OpenAPI

If you are growing API applications, you favor to make positive you are the use of Swagger. It makes it handy to record and take a look at your APIs.

ASP.NET has traditionally furnished built-in performance that is relatively comparable for SOAP net offerings created with WCF. If you are the use of Web API or MVC for RESTful APIs, you in reality prefer to use Swagger.

Conclusion

ASP.NET Core has been a first-rate improve over preceding versions. In this article, we highlighted some of the key aspects you have to be conscious of. Some are new, some are simply key aspects of ASP.NET that have existed for a while.

Our products, Prefix and Retrace, each grant amazing aid for ASP.NET Core. If monitoring the overall performance of your functions is important, you certainly favor to checkout Retrace.

65 Shares:
Leave a Reply

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

fifteen + eight =

You May Also Like