Create an account


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ASP.NET Core updates in .NET 5 Preview 6

#1
ASP.NET Core updates in .NET 5 Preview 6

<div style="margin: 5px 5% 10px 5%;"><img src="https://www.sickgaming.net/blog/wp-content/uploads/2020/06/asp-net-core-updates-in-net-5-preview-6.png" width="58" height="58" title="" alt="" /></div><div><div class="row justify-content-center">
<div class="col-md-4">
<div><img loading="lazy" src="https://www.sickgaming.net/blog/wp-content/uploads/2020/06/asp-net-core-updates-in-net-5-preview-6.png" width="58" height="58" alt="Avatar" class="avatar avatar-58 wp-user-avatar wp-user-avatar-58 photo avatar-default"></p>
<p>Sourabh</p>
</div>
</div>
</div>
<div class="entry-meta">
<p>June 25th, 2020</p>
</p></div>
<p><!-- .entry-meta --> </p>
<p><a href="https://devblogs.microsoft.com/dotnet/announcing-net-5-0-preview-6/">.NET 5 Preview 6 is now available</a> and is ready for evaluation. Here’s what’s new in this release:</p>
<ul>
<li>Blazor WebAssembly template now included</li>
<li>JSON extension methods for <code>HttpRequest</code> and <code>HttpResponse</code></li>
<li>Extension method to allow anonymous access to an endpoint</li>
<li>Custom handling of authorization failures</li>
<li>SignalR Hub filters</li>
</ul>
<h2>Get started</h2>
<p>To get started with ASP.NET Core in .NET 5.0 Preview 6 <a href="https://dotnet.microsoft.com/download/dotnet-core/5.0">install the .NET 5.0 SDK</a>.</p>
<p>You need to use <a href="https://visualstudio.microsoft.com/vs/preview/">Visual Studio 2019 16.7</a> or <a href="https://visualstudio.microsoft.com/">Visual Studio 2019 for Mac 8.6</a> to use .NET 5.0. Install the latest version of the <a href="https://code.visualstudio.com/Docs/languages/csharp">C# extension</a>, to use .NET 5.0 with <a href="https://visualstudio.microsoft.com/">Visual Studio Code</a>.</p>
<h2>Upgrade an existing project</h2>
<p>To upgrade an existing ASP.NET Core 5.0 Preview 5 app to ASP.NET Core 5.0 Preview 6:</p>
<ul>
<li>Update all Microsoft.AspNetCore.* package references to <code>5.0.0-preview.6.*</code>.</li>
<li>Update all Microsoft.Extensions.* package references to <code>5.0.0-preview.6.*</code>.</li>
</ul>
<p>See the full list of <a href="https://github.com/aspnet/announcements/issues?q=is%3Aopen+is%3Aissue+milestone%3A5.0+label%3A%22Breaking+change%22">breaking changes</a> in ASP.NET Core 5.0.</p>
<p>That’s it! You should now be all set to use .NET 5 Preview 6.</p>
<h2>What’s new?</h2>
<h3>Blazor WebAssembly template now included</h3>
<p>The Blazor WebAssembly template is now included in the .NET 5 SDK along with the Blazor Server template. To create a Blazor WebAssembly project, simply run <code>dotnet new blazorwasm</code>.</p>
<h3>JSON extension methods for <code>HttpRequest</code> and <code>HttpResponse</code></h3>
<p>You can now easily read and write JSON data from an <code>HttpRequest</code> and <code>HttpResponse</code> using the new <code>ReadFromJsonAsync</code> and <code>WriteAsJsonAsync</code> extension methods. These extension methods use the <code>System.Text.Json</code> serializer to handle the JSON data. You can also check if a request has a JSON content type using the new <code>HasJsonContentType</code> extension method.</p>
<p>The JSON extension methods can be combined with endpoint routing to create JSON APIs in a style of programming we call “route to code”. It is a new option for developers who want to create basic JSON APIs in a lightweight way. For example, a web app that has only a handful of endpoints might choose to use route to code rather than the full functionality of ASP.NET Core MVC.</p>
<pre><code class="cs">endpoints.MapGet("/weather/{city:alpha}", async context =&gt;
{ var city = (string)context.Request.RouteValues["city"]; var weather = GetFromDatabase(city); await context.Response.WriteAsJsonAsync(weather);
});
</code></pre>
<p>Find out more about the JSON extension methods in a <a href="https://channel9.msdn.com/Shows/On-NET/ASPNET-Core-Series-Route-to-Code">recent On .NET interview about route to code</a>.</p>
<h3>Extension method to allow anonymous access to an endpoint</h3>
<p>You can now allow anonymous access to an endpoint using the simpler <code>AllowAnonymous</code> extension method when using endpoint routing.</p>
<pre><code class="csharp">public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{ app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); app.UseEndpoints(endpoints =&gt; { endpoints.MapGet("/", async context =&gt; { await context.Response.WriteAsync("Hello World!"); }) .AllowAnonymous(); });
}
</code></pre>
<h3>Custom handling of authorization failures</h3>
<p>Custom handling of authorization failures is now easier with the new <code>IAuthorizationMiddlewareResultHandler</code> interface that is invoked by the AuthorizationMiddleware. The default implementation remains the same, but a custom handler can be be registered in DI which allows things like custom HTTP responses based on why authorization failed. A sample that demonstrates usage of the <code>IAuthorizationMiddlewareResultHandler</code> can be found <a href="https://github.com/dotnet/aspnetcore/blob/master/src/Security/samples/CustomAuthorizationFailureResponse/Authorization/SampleAuthorizationMiddlewareResultHandler.cs">here</a>.</p>
<h3>SignalR Hub filters</h3>
<p>Hub filters, called Hub pipelines in ASP.NET SignalR, is a feature that allows you to run code before and after Hub methods are called, similar to how middleware lets you run code before and after an HTTP request. Common uses include logging, error handling, and argument validation.</p>
<p>You can read more about this Hub filters on the <a href="https://docs.microsoft.com/aspnet/core/signalr/hub-filters?view=aspnetcore-5.0">docs page</a>.</p>
<h2>Give feedback</h2>
<p>We hope you enjoy this release of ASP.NET Core in .NET 5! We are eager to hear about your experiences with this latest .NET 5 release. Let us know what you think by filing issues on <a href="https://github.com/dotnet/aspnetcore/issues">GitHub</a>.</p>
<p>Thanks for trying out ASP.NET Core!</p>
</div>


https://www.sickgaming.net/blog/2020/06/...preview-6/
Reply



Forum Jump:


Users browsing this thread:
2 Guest(s)

Forum software by © MyBB Theme © iAndrew 2016