Buzzzz!! NEW ASP.NET Core 7 has been Released! What’s New?! – Windows ASP.NET Core Hosting 2024 | Review and Comparison

Microsoft has rolled out the production release of .NET 7, the latest version of the company’s cross-platform, open-source software development platform. The update brings performance enhancements, C# language upgrades, and a roster of cloud-native, container-based development capabilities.

Key themes of the release cover enabling developers to write performant web APIs and build cloud-native applications and deploy them across Linux. Developer productivity and containerisation of projects also are emphasised, along with setting up CI/CD workflows in GitHub actions.

As part of the big release, Microsoft detailed what’s new for ASP.NET Core, starting with Blazor, used to create Single Page Applications (SPA). For example, developers can now create Blazor custom elements to dynamically render Razor components from other SPA frameworks including Angular or React. 

In this article we have compiled all the new .NET 7 features based on Microsoft Docs and their release notes. Discover all .NET 7 features!

Faster, Lighter Apps (Native AOT)

Native AOT (Ahead-of-time) is another of the new improvements and novelties that Microsoft brings this time in .NET 7. After a while, the experimental Native AOT project has become the main focus of Microsoft’s development. As many of us have been asking for a long time, Microsoft has decided to bring us a couple of updates to Native AOT.

For those who don’t know what Native AOT is, Ahead-of-time (simply AOT) generates code at compile-time instead of run-time.

At this time, Microsoft already offers ReadyToRun, also called RTR (client/server applications) and Mono AOT (mobile and WASM applications) for this purpose. In addition, Microsoft adds that Native AOT does not replace Mono AOT or WASM.

Native AOT is characterized by what its name indicates: It generates code at compile time but in Native. Its biggest advantage is the performance improvement, according to Microsoft mainly in:

  • Startup time
  • Memory usage
  • Disk size
  • Access to restricted platforms

System.Composition.Hosting

Apart from Native AOT, we have many more new features such as the Managed Extensibility Framework update: Now the new APIs will allow you to add a single object instance to the System.Composition.Hosting container:

namespace System.Composition.Hosting
{
    public class ContainerConfiguration
    {
        public ContainerConfiguration WithExport<TExport>(TExport exportedInstance);
        public ContainerConfiguration WithExport<TExport>(TExport exportedInstance, string contractName = null, IDictionary<string, object> metadata = null);

        public ContainerConfiguration WithExport(Type contractType, object exportedInstance);
        public ContainerConfiguration WithExport(Type contractType, object exportedInstance, string contractName = null, IDictionary<string, object> metadata = null);
    }
}

You can check the original proposal: Inject existing object into MEF2

Observability

Microsoft also brings us improvements in support for the cloud-native specification (OpenTelemetry). Although it is still under development in .NET 7, it has been added Allow samplers to modify tracestate and Samplers should be allowed to modify tracestate. Here we can see the Microsoft example:

//  ActivityListener Sampling callback
    listener.Sample = (ref ActivityCreationOptions<ActivityContext> activityOptions) =>
    {
        activityOptions = activityOptions with { TraceState = "rojo=00f067aa0ba902b7" };
        return ActivitySamplingResult.AllDataAndRecorded;
    };

Reduced start-up time (Write-Xor-Execute)

As we have already seen at the beginning, Microsoft has decided to focus mainly on performance improvements and this one is no exception. Now with Reimplement stubs to improve performance we have seen an improvement in startup time that, according to Microsoft, is up to 10–15%.

This is mainly due to a large reduction in the number of modifications after code creation at runtime.

Let’s check the benchamarks:

Generating X.500 names more robustly

Also in this preview, Microsoft has focused on cryptographic security. That is why building an X500DistinguishedName is now much easier and more secure.

For those who don’t know this about the construction of an X.500 name, it used to be done with string manipulation (simple literal or string formatted). This way:

request = new CertificateRequest($"CN={subjectName},OU=Test,O=""Fabrikam, Inc.""", ...);

The main problem with this is that the quote, comma or any other element influences the parser. Microsoft’s solution has been to add the X500DistinguishedName class. There would be no problem since each method can only operate on a single RDN (Relative Distinguished Name).

Let’s look at the Microsoft example:

X500DistinguishedNameBuilder nameBuilder = new();
nameBuilder.AddCommonName(subjectName);
nameBuilder.AddOrganizationalUnitName("Test");
nameBuilder.AddOrganizationName("Fabrikam, Inc.");

request = new CertificateRequest(nameBuilder.Build(), ...);

The union of Blazor and .NET MAUI

As we already know, Blazor is aweb application development framework and one of its main features is that Blazor has the ability to run the application views on the client side — and not on the server and then teach the browser the HTML.

?Interesting fact: In case you didn’t know, the name Blazor comes from the union of two words: Browser and Razor — the .NET HTML view generation engine.

And as we also learned in a previous article, .NET MAUI is the Framework Microsoft is working on that focuses on mobile applications. And if you’re asking yourself… Yes, many people say that .NET MAUI will be the evolution of Xamarin.

This is where Microsoft is going to do a “milkshake” with Blazor and .NET MAUI that will become Blazor Hybrid. Let’s take a closer look.

Blazor Hybrid: The revolution?

In order to explain it in the best possible way, we must go a little bit to the past (specifically 2018), which was the year of the initial release of Blazor (web). At that time it was only possible to build web pages with HTML, CSS and also with C#. This was unfeasible to think about several years ago, but now Microsoft wants to go a step further — and strong: Now, they are working on bringing together the main features and functions of Blazor and .NET MAUI to Blazor Hybrid.

Cloud Native and containers

Another new feature explained by Microsoft is the Modern Cloud. As we already know, cloud-native applications are usually built from scratch to take advantage of all the resources of containers and databases. This architecture is very good because it allows scaling applications very easily with the creation of autonomous subsystems. This, in turn, reduces costs in the long run.

What .NET will bring will be the facilitation of the creation of cloud-native applications with different kinds of improvements in the developer experience — thanks Microsoft for thinking of us.

Besides, it will simplify quite a lot the installation and configuration of authentication and authorization systems. And of course, as always, small performance improvements at application runtime.

Easier upgrading .NET applications

As we all know — and some have suffered through it, migrating older applications to .NET 6 has not been the easiest thing in the world. That’s why Microsoft is bringing new upgrade enhancements for older applications. The main points are:

  • More code analyzers
  • More code checkers
  • Compatibility checkers

All of this will come along with the.NET Upgrade Assistant that will greatly help in getting those applications upgraded, saving the developer time — thanks Microsoft.

Single Memory Cache

Now you can instantiate a single memory cache with the AddMemoryCache API. In addition, you will be able to get it injected so you can call GetCurrentStatistics . Let’s check Microsoft example:

// when using `services.AddMemoryCache(options => options.TrackStatistics = true);` to instantiate

    [EventSource(Name = "Microsoft-Extensions-Caching-Memory")]
    internal sealed class CachingEventSource : EventSource
    {
        public CachingEventSource(IMemoryCache memoryCache) { _memoryCache = memoryCache; }
        protected override void OnEventCommand(EventCommandEventArgs command)
        {
            if (command.Command == EventCommand.Enable)
            {
                if (_cacheHitsCounter == null)
                {
                    _cacheHitsCounter = new PollingCounter("cache-hits", this, () =>
                        _memoryCache.GetCurrentStatistics().CacheHits)
                    {
                        DisplayName = "Cache hits",
                    };
                }
            }
        }
    }

In addition, Microsoft leaves an example of how it would help us to see stats with the dotnet-counters tool (check it here):

Press p to pause, r to resume, q to quit.
    Status: Running

[System.Runtime]
    CPU Usage (%)                                      0
    Working Set (MB)                                  28
[Microsoft-Extensions-Caching-MemoryCache]
    cache-hits                                       269

Multiple Memory Cache

As in the previous feature, which allowed instantiating a single cache memory, we can also instantiate multiple memory cache with GetCurrentStatistics . Let’s check this Microsoft example:

static Meter s_meter = new Meter("Microsoft.Extensions.Caching.Memory.MemoryCache", "1.0.0");
static IMemoryCache? mc1;
static IMemoryCache? mc2;

static void Main(string[] args)
{
   s_meter.CreateObservableGauge<long>("cache-hits", GetCacheHits);
   mc1 = new MemoryCache(new MemoryCacheOptions() { TrackStatistics = true, SizeLimit = 30 });
   mc2 = new MemoryCache(new MemoryCacheOptions() { TrackStatistics = true, SizeLimit = 30 });

   // call to: mc1.TryGetValue(key1, out object? value)
   // or: mc2.TryGetValue(key2, out value2)
   // increments TotalHits
}

// metrics callback for cache hits
static IEnumerable<Measurement<long>> GetCacheHits()
{
   return new Measurement<long>[]
   {
      new Measurement<long>(mc1!.GetCurrentStatistics()!.TotalHits, new KeyValuePair<string,object?>("CacheName", "mc1")),
      new Measurement<long>(mc2!.GetCurrentStatistics()!.TotalHits, new KeyValuePair<string,object?>("CacheName", "mc2")),
   };

And also, as in the previous feature, Microsoft shows us that we can also measure stats with the dotnet-counters tool (check it here): 

Press p to pause, r to resume, q to quit.
    Status: Running

[System.Runtime]
    CPU Usage (%)                                      0
    Working Set (MB)                                  14
[Microsoft.Extensions.Caching.Memory.MemoryCache]
    cache-hits
        CacheName=mc1                             13,204
        CacheName=mc2                             13,204

New Tar APIs

We will now have cross-platform APIS with which we can extract and modify (read and write) tar archives. As usual, Microsoft has shown examples so let’s take a look at some of them:

.NET 7 Archive Tar API

// Generates a tar archive where all the entry names are prefixed by the root directory 'SourceDirectory'
TarFile.CreateFromDirectory(sourceDirectoryName: "/home/dotnet/SourceDirectory/", destinationFileName: "/home/dotnet/destination.tar", includeBaseDirectory: true);

.NET 7 Extract Tar API

// Extracts the contents of a tar archive into the specified directory, but avoids overwriting anything found inside
TarFile.ExtractToDirectory(sourceFileName: "/home/dotnet/destination.tar", destinationDirectoryName: "/home/dotnet/DestinationDirectory/", overwriteFiles: false);

OSR (On Stack Replacement)

OSR (On Stack Replacement) is a great complement to tiered compilation. It allows, in the middle of the execution of a method, to change the code that is being executed by the methods that are being executed at the moment.

Improved Regex source generator

The new Regex Source Generator means that you can shave off up to 5x the time spent optimizing patterns from our compiled engine without having to sacrifice any of the associated performance benefits.

Additionally, because it operates within a partial class, there is no overhead of compiling-time for instances when users know their pattern at runtime. With this feature, if your pattern can be known at compile-time, then this generator is recommended instead of our traditionally compiler based approach.

All you need to do is set up a partial declaration with an attribute called RegexGenerator which points back to the method that will return an already precompiled regular expression object (with all other features enabled). Our generator will take care of creating that method and updating it as needed according to changes made to either the original string or passed in options (like case sensitivity etc…).

Improved System.Reflection Performance

Starting with the performance enhancements of the new .NET 7 features, we have first the enhancement of the System.Reflection namespace.The System.Reflection namespace is responsible for containing and storing types by metadata, to facilitate the retrieval of stored information from modules, members, assemblies and more.

They are mostly used for manipulating instances of loaded types and with them you can create types dynamically in a simple way.

With this update by Microsoft, now in .NET 7 the overhead when invoking a member using reflection has been reduced considerably. If we talk about numbers, according to the last benchmark provided by Microsoft (made with the package BenchmarkDotNet ) you can see up to 3–4x faster.

using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using System.Reflection;

namespace ReflectionBenchmarks
{
    internal class Program
    {
        static void Main(string[] args)
        {
            BenchmarkRunner.Run<InvokeTest>();
        }
    }

    public class InvokeTest
    {
        private MethodInfo? _method;
        private object[] _args = new object[1] { 42 };

        [GlobalSetup]
        public void Setup()
        {
            _method = typeof(InvokeTest).GetMethod(nameof(InvokeMe), BindingFlags.Public | BindingFlags.Static)!;
        }

        [Benchmark]
        // *** This went from ~116ns to ~39ns or 3x (66%) faster.***
        public void InvokeSimpleMethod() => _method!.Invoke(obj: null, new object[] { 42 });

        [Benchmark]
        // *** This went from ~106ns to ~26ns or 4x (75%) faster. ***
        public void InvokeSimpleMethodWithCachedArgs() => _method!.Invoke(obj: null, _args);

        public static int InvokeMe(int i) => i;
    }
}

Loop Optimizations

This improvement is not very impressive but it still manages to improve performance significantly. This time Microsoft has decided to proceed with the elimination of the initialization conditions of the loop cloning variables:

Critical Performance Tags — 83% Faster

Microsoft tells us that it is now possible to expose tag enumerator methods. This is especially intended for critical scenarios where performance is of vital importance and can now be achieved using ActivityEvent and ActivityLink.

There are many more features that you can find using latest ASP.NET Core 7.

3 Best ASP.NET Core 7 Web Hosting Providers!

Let’s uncover top 3 Windows ASP.NET hosting provider that support for latest ASP.NET Core 7 on their hosting environment.

1. ASPHostPortal – Best Choice ASP.NET Core 7 Hosting

Since 2008, ASPHostPortal has been growing into one of the best cheap ASP.NET hosting provider that offer affordable ASP.NET hosting provider. They offer top quality and the latest ASP.NET Core 7 hosting on their ASP.NET hosting environment.

ASPHostPortal is the #1 ASP.NET web hosting company according to us and millions users. ASPHostPortal is one of top recommended Windows ASP.NET Hosting provider, they provide reliable and cheap ASP.NET hosting and they have huge support, you can easily contact them anytime you want.

ASPHostPortal ensures low latency services via its giant SSD based infrastructure. With many data center locations that are spread around the globe, ASPHostPortal is among the few companies with such an amount of datacenter choices. So you will get multiple locations in North America, Asia, and Europe regions. So just imagine the probability to locate near your targeted audience.

ASPHostPortal has various ASP.NET Core 7 shared hosting plan which start from with an affordable price. There are 4 favorite ASP.NET Core hosting plans which start from Host One, Host Two, Host Three, and Host Four. Host One plan start with $5.00/month. Host Two start with $9.00/month, Host Three is the most favorite plan start from $14.00/month and Host Four start with $23.00/month. That was previous price and if you purchase their ASP.NET Core hosting plan via our site, you can get more discount price. Host One priced at $3.81/month, $7.21/month, $11.46/month, and $18.27/month All of their ASP.NET Core hosting plan allows user host unlimited domains, unlimited email accounts, at least 1 MSSQL and 1 MySQL database.

Customer can always start from their Host One plan and this plan has support latest ASP.NET Core 6 hosting. For more information, please visit their site at http://www.asphostportal.com.

ASPHostPortal ASP.NET Hosting

2. HostForLIFE.eu – Favourite ASP.NET Core 7 Hosting for European Users

HostForLIFE.eu is a ASP.NET Core 7 hosting provider only engaged in Windows-based hosting solutions. It owns a big advantage that is short distance between its offices and the datacenter. HostForLIFE.eu has many data centers in Europe. This is big advantages for customers in Europe. Customer can choose their Paris, London, Frankfurt, Amsterdam, and also their newest Italy datacenters if you register their ASP.NET hosting plan.

It’s great option if you need European data center. HostForLIFE offers 4 main shared ASP.NET Core 7 hosting plan, named Classic, Budget, Economy, and Business plan. All this plan include unlimited disk space, unlimited bandwith, unlimited email account, unlimited hosted domains. All this plan also include MSSQL and MySQL database.

HostForLIFE ASP.NET Core 7 Hosting plan start from €2.97/month, €4.67/month, €6.80/month, and €9.34/month. A 30-day money back guarantee is provided to eliminate purchasing risks.

Customer can always start from their Classic plan and this plan has support the latest ASP.NET hosting, this plan is fairly cheap with start from only €2.97/month. And now the exclusive discount comes to customers, customer can get FREE domain by using coupon code “HFLDOMAIN” and double MSSQL database by using coupon code “HFLSQL”.

The vendor offers a variety of add-ons, so before finalizing the purchase, make sure to uncheck any unnecessary services, so avoid additional costs. Their ASP.NET Core 7 hosting comes with a Plesk control panel that puts tons of functions under your few mouse clicks.

At any time, if you need help, you can contact their expert team via ticketing system. Also, there is a link to the informative knowledge base on their website. Overall, HostForLIFE.eu is a cost-effective best ASP.NET Core 7 hosting that offers pretty unlimited resources and more security to your investment.

hostforlife

For more information, please visit their official site at https://www.hostforlife.eu

3. UKWindowsHostASP.NET – Best ASP.NET Core 7 Hosting for SMALL Apps

UKWindowsHostASP.NET is known as one of the favorite places for developers. UKWindowsHostASP.NET backed by cloud infrastructure. In cloud hosting, multiple machines act as a single, so compared to shared hosting your applications/website does not rely on a single server.

This company utilizes 5 datacenters. You can choose their London, Frankfurt, Paris, Milan, and also their Amsterdam data center while registering their ASP.NET hosting services. They have redundant resources to support UKWindowsHostASP.NET servers. Note that UKWindowsHostASP.NET purchases servers only from Dell.

Each of their plans equipped with RAID-10 SSD storage, which is known for reliability and data protection. They store everything (Operating system, databases, and other files, etc.) on SSD to ensure speedy services. Instead of host ASP.NET Core 7 projects, UKWindowsHostASP.NET also support multiple versions of ASP.NET, such as Classic ASP, 2.0, 3.5, and also 4.0.

Customer can easily deploy ASP.NET site via their Plesk panel. There are 3 options to choose while deploying your ASP.NET files, you can choose FTP, File Manager, and also WebDeploy. Customer can always start from their Economy plan (£5.99/month) which include 5 GB storage, 50 GB bandwith, full trust, 1 MSSQL, 2 MySQL, and unlimited email accounts. Plus their 24*7 support is awesome.

In terms of refund policy, the company commits to giving all hosting fees back to the customer who is not completely content with the service received. The full money-back guarantee is applicable to the first 30 calendar days of the term. No Hidden Fees is also promised.