ASP.NET is one of the most successful web application development frameworks by Microsoft.
With every update, new and extended features are added that help developers deploy highly scalable and high-performance web applications.
Features to build better applications with ASP.NET Core are : -
1. Cross-platform & container support
With the introduction of .NET Core, you can now create ASP.NET applications and deploy them to Windows, Linux and macOS.
2. High performance
The introduction of ASP.NET Core and the Kestrel web server, ASP.NET is touted as one of the fastest web application frameworks available.
The new Kestrel web server was redesigned from the ground up to take advantage of asynchronous programming models, be much more lightweight and fast.
3. Asynchronous via async/await
One of the reasons ASP.NET Core is faster is its extensive use of asynchronous patterns within 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
MVC was tailored to creating web applications that served up HTML.
Web API was designed to create RESTful services using JSON or XML.
With ASP.NET Core, MVC and Web API have been merged together. MVC could always return JSON data instead of HTML.
ASP.NET Core are sort of a replacement for WebForms while using the familiar Razor syntax.
5. Dependency Injection
It is the preferred way that things like logging contexts, database contexts and other things are passed 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");
}
}
6. WebSockets & SignalR
ASP.NET has first class support for WebSockets.
This can be used to persist long running connections and communicate back and forth with the browser.
SignalR is a full framework that is also available that makes it easy handle common scenarios.
7. Cross-Site Request Forgery (CSRF) Protection
CSRF is in referencing to hijacking users authenticated session to perform an action that they did not initiate.
For example, let’s pretend that you log in to your bank account and then navigate to a different website. If that other website could do a POST to your bank website to transfer funds, that would be a bad thing. It could potentially do that if your online session on the banking website is valid and the bank does not properly validate requests.
ASP.NET has a good framework that is available to prevent these types of attacks. It generates anti-forgery tokens.
8. “Self hosted” Web Applications
Sometimes you need to make a web application that will be deployed on to a desktop and not a server running IIS.
Our free ASP.NET profiler, Prefix is a perfect example of this.
Its front end is all HTML that is loaded from an ASP.NET application running as a Windows Service.
You can create a self-hosted ASP.NET web application several different ways.
In .NET 4.5 you could accomplish it by using Owin, Nancy or WCF.
9. Action Filters
One of the great features of ASP.NET is the support for extensible filters. This allows you to implement functionality that can be applied to an entire controller or action without modifying the action itself.
Filters are used to specify caching, error handling, authorization or any custom logic 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");
}
}
}
10. Extensible Output Caching
This feature allows ASP.NET to cache the output generated by a page and serve this cached content for future requests.
It stores the data that is not updated frequently and outputs that specific data from a cached location.
11. Globalization and Localization
ASP.NET makes it easy to localize dates, numbers and the text within your web application.
If you want your application to be used across the globe, localization will be very important to you.
ASP.NET enables customizing your application for multiple languages via resource files. These resource files are considered as the central repository where all texts are kept and web pages can read this resource file and get labels populated. There are two types of resources:
Local Resources – specific for a page (i.e., there will be local resource file for every page)
Global Resources – common for the whole website (i.e., one resource file accessed by all pages)
12. Swagger OpenAPI
If you are creating API applications, you want to make sure you are using Swagger.
It makes it easy to document and test your APIs.
ASP.NET has historically provided built-in functionality that is pretty similar for SOAP web services created with WCF.
If you are using Web API or MVC for RESTful APIs, you definitely want to use Swagger.
No comments:
Post a Comment