{"id":42739,"date":"2022-10-11T10:00:00","date_gmt":"2022-10-11T17:00:00","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/dotnet\/?p=42739"},"modified":"2022-10-31T11:12:06","modified_gmt":"2022-10-31T18:12:06","slug":"asp-net-core-updates-in-dotnet-7-rc-2","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/dotnet\/asp-net-core-updates-in-dotnet-7-rc-2\/","title":{"rendered":"ASP.NET Core updates in .NET 7 Release Candidate 2"},"content":{"rendered":"<p><a href=\"https:\/\/devblogs.microsoft.com\/dotnet\/announcing-dotnet-7-rc-2\">.NET 7 Release Candidate 2 (RC2) is now available<\/a> and includes many great new improvements to ASP.NET Core.<\/p>\n<p>Here&#8217;s a summary of what&#8217;s new in this preview release:<\/p>\n<ul>\n<li>Output caching improvements<\/li>\n<li>Dynamic authentication requests with msal.js<\/li>\n<li>Improved diagnostics for authentication in Blazor WebAssembly<\/li>\n<li>WebAssembly multithreading (experimental)<\/li>\n<\/ul>\n<p>For more details on the ASP.NET Core work planned for .NET 7 see the full <a href=\"https:\/\/aka.ms\/aspnet\/roadmap\">ASP.NET Core roadmap for .NET 7<\/a> on GitHub.<\/p>\n<h2>Get started<\/h2>\n<p>To get started with ASP.NET Core in .NET 7 Release Candidate 2, <a href=\"https:\/\/dotnet.microsoft.com\/download\/dotnet\/7.0\">install the .NET 7 SDK<\/a>.<\/p>\n<p>If you&#8217;re on Windows using Visual Studio, we recommend installing the latest <a href=\"https:\/\/visualstudio.com\/preview\">Visual Studio 2022 preview<\/a>. If you&#8217;re on macOS, we recommend installing the latest <a href=\"https:\/\/visualstudio.microsoft.com\/vs\/mac\/preview\/\">Visual Studio 2022 for Mac preview<\/a>.<\/p>\n<p>To install the latest .NET WebAssembly build tools, run the following command from an elevated command prompt:<\/p>\n<pre><code class=\"language-console\">dotnet workload install wasm-tools<\/code><\/pre>\n<h2>Upgrade an existing project<\/h2>\n<p>To upgrade an existing ASP.NET Core app from .NET 7 RC1 to .NET 7 RC2:<\/p>\n<ul>\n<li>Update all Microsoft.AspNetCore.* package references to <code>7.0.0-rc.2.*<\/code>.<\/li>\n<li>Update all Microsoft.Extensions.* package references to <code>7.0.0-rc.2.*<\/code>.<\/li>\n<\/ul>\n<p>See also the full list of <a href=\"https:\/\/docs.microsoft.com\/dotnet\/core\/compatibility\/7.0#aspnet-core\">breaking changes<\/a> in ASP.NET Core for .NET 7.<\/p>\n<h2>Output caching improvements<\/h2>\n<p>Output caching was improved in .NET 7 RC2 based on preview feedback from users.<\/p>\n<h3>Binary serialization<\/h3>\n<p>In this version, output caching stores the content of the cached entries in a binary format. Previously it was using JSON. This new format is faster and smaller.<\/p>\n<h3>Option to not vary by host<\/h3>\n<p>By default, cached entries are unique per HTTP domain name. A few users reported the need for cached entries to be shared across domain names. For this purpose, we introduced a new <code>SetVaryByHost<\/code> option:<\/p>\n<pre><code class=\"language-csharp\">builder.Services.AddOutputCache(options =&gt;\r\n{\r\n    options.AddBasePolicy(builder =&gt; builder.SetVaryByHost(false));\r\n}<\/code><\/pre>\n<h3>Improved vary-by rules<\/h3>\n<p>Some changes were made to the API to make its usage simpler and more consistent.<\/p>\n<p>For example, you can now create an <code>OutputCachePolicyBuilder<\/code> instance that doesn&#8217;t contain the default policy, so you can specify your own logic.<\/p>\n<p>We also prefixed most builder methods with <code>SetXxxxx<\/code> to make it obvious these methods will update an existing property of the builder:<\/p>\n<pre><code class=\"language-csharp\">options.AddBasePolicy(b =&gt; b.SetVaryByQuery(\"*\").SetLocking(true));<\/code><\/pre>\n<h2>Dynamic authentication requests with msal.js<\/h2>\n<p>In .NET 7 RC1 we introduced support for making dynamic authentication requests with custom parameters in Blazor WebAssembly apps. With .NET 7 RC2, this functionality is now available when using the Microsoft Identity Platform via the built-in msal.js integration. For details on making dynamic authentication requests in Blazor WebAssembly see the <a href=\"https:\/\/devblogs.microsoft.com\/dotnet\/asp-net-core-updates-in-dotnet-7-rc-1\/#dynamic-authentication-requests-in-blazor-webassembly\">Dynamic authentication requests in Blazor WebAssembly<\/a> section of the .NET 7 RC1 release announcement post.<\/p>\n<h2>Improved diagnostics for authentication in Blazor WebAssembly<\/h2>\n<p>To help diagnose authentication issues in Blazor WebAssembly apps we added detailed logging that you can enable using the following logging configuration:<\/p>\n<pre><code class=\"language-json\">\"Logging\": {\r\n    \"LogLevel\": {\r\n        \"Microsoft.AspNetCore.Components.WebAssembly.Authentication\": \"Debug\"\r\n    }\r\n}<\/code><\/pre>\n<p>See <a href=\"https:\/\/learn.microsoft.com\/aspnet\/core\/blazor\/fundamentals\/configuration?view=aspnetcore-6.0#logging-configuration\">Logging configuration<\/a> for additional details on how to configure logging in Blazor WebAssembly apps.<\/p>\n<h2>WebAssembly multithreading (experimental)<\/h2>\n<p>The <code>wasm-experimental<\/code> workload now includes support for multi-threaded .NET apps on WebAssembly using <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/Web_Workers_API\/Using_web_workers\">Web Workers<\/a>. This is a new .NET runtime capability. Multithreading support hasn&#8217;t been integrated yet into Blazor WebAssembly apps (planned for .NET 8), but you can still try it out in preview form using the experimental WebAssembly Browser App template.<\/p>\n<p>To use WebAssembly multithreading:<\/p>\n<ul>\n<li>Install the <code>wasm-experimental<\/code> workload:\n<pre><code class=\"language-console\">dotnet workload install wasm-experimental<\/code><\/pre>\n<\/li>\n<li>Create a new <code>wasmbrowser<\/code> app:\n<pre><code class=\"language-console\">dotnet new wasmbrowser<\/code><\/pre>\n<\/li>\n<li>Add the <code>WasmEnableThreads<\/code> property to the project file to enable threading:\n<pre><code class=\"language-xml\">&lt;PropertyGroup&gt;\r\n  &lt;WasmEnableThreads&gt;true&lt;\/WasmEnableThreads&gt;\r\n&lt;\/PropertyGroup&gt;<\/code><\/pre>\n<\/li>\n<li>Add a reference to the Microsoft.NET.WebAssembly.Threading package. This package provides reference assemblies that prevent warnings about using threading APIs in the browser:\n<pre><code class=\"language-console\">dotnet add package --prerelease Microsoft.NET.WebAssembly.Threading<\/code><\/pre>\n<\/li>\n<li>Create and run a new thread.\n<pre><code class=\"language-csharp\">using System;\r\nusing System.Threading;\r\nusing System.Runtime.Versioning;\r\nusing System.Runtime.InteropServices.JavaScript;\r\n\r\n[assembly:SupportedOSPlatform(\"browser\")]\r\n\r\nnew Thread(SecondThread).Start();\r\nConsole.WriteLine($\"Hello, Browser from the main thread {Thread.CurrentThread.ManagedThreadId}\");\r\n\r\nstatic void SecondThread()\r\n{\r\n    Console.WriteLine($\"Hello from Thread {Thread.CurrentThread.ManagedThreadId}\");\r\n    for (int i = 0; i &lt; 5; ++i)\r\n    {\r\n        Console.WriteLine($\"Ping {i}\");\r\n        Thread.Sleep(1000);\r\n    }\r\n}<\/code><\/pre>\n<\/li>\n<li>Run the app and browser to the app URL:\n<pre><code class=\"language-console\">dotnet run<\/code><\/pre>\n<\/li>\n<li>(Optional) Publish and serve the app with a web server such as <a href=\"https:\/\/www.nuget.org\/packages\/dotnet-serve\">dotnet-serve<\/a>. Note that <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/SharedArrayBuffer#security_requirements\">cross origin isolation<\/a> must be enabled by serving the COOP and COEP headers\n<pre><code class=\"language-console\">dotnet publish -c Release\r\ndotnet serve -h \"Cross-Origin-Opener-Policy:same-origin\" -h \"Cross-Origin-Embedder-Policy:require-corp\" --directory bin\/Release\/net7.0\/browser-wasm\/AppBundle\/<\/code><\/pre>\n<\/li>\n<li>Open the served URL in a browser and view the output in the browser developer console. (note: Chrome, Edge or Safari; at this time Firefox is not supported until <a href=\"https:\/\/bugzilla.mozilla.org\/show_bug.cgi?id=1540913\">Mozilla #1540913<\/a> is fixed)\n<pre><code class=\"language-console\">Hello from Thread 2\r\nHello, Browser from the main thread 1\r\nPing 0\r\nPing 1\r\nPing 2\r\nPing 3\r\nPing 4<\/code><\/pre>\n<\/li>\n<\/ul>\n<p>The completed example is available at https:\/\/github.com\/lambdageek\/hithread.<\/p>\n<p>Notes and known issues with .NET multithreading on WebAssembly:<\/p>\n<ul>\n<li>By default, the app will create a pool of four Web Workers to execute .NET threads. To control the number of workers that are created at app startup, configure the <code>_WasmPThreadPoolSize<\/code> property (subject to change in a future release). The maximum parallelism of your app must not exceed the worker pool size.<\/li>\n<li>A <code>SynchronizationContext<\/code> is used on the browser thread by default. If you do not use <code>ConfigureAwait(false)<\/code> when awaiting asynchronous operations, they will be scheduled on the browser thread. Conversely, not using <code>ConfigureAwait<\/code> allows your asynchronous operations to return to the browser thread in order to interact with the DOM or other JS libraries that are only available on the main thread.<\/li>\n<li>Multithreading requires that <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/SharedArrayBuffer#security_requirements\">cross origin isolation<\/a> is enabled by serving the COOP and COEP headers. This will restrict the functionality of the site: Enabling cross-origin isolation blocks loading cross-origin resources that you don&#8217;t explicitly opt-in, and it will prevent your top-level document from being able to communicate with popup windows.<\/li>\n<li>The build properties <code>RunAOTCompilation<\/code> and <code>WasmEnableSIMD<\/code> are supported with multithreading.<\/li>\n<li><code>JSImport<\/code> and <code>JSExport<\/code> only work from the main browser thread.<\/li>\n<li>WebSocket operations are only supported on the main browser thread.<\/li>\n<li>Debugging multithreaded code on WebAssembly is not yet supported.<\/li>\n<li>Threading does not work in Firefox yet due to <a href=\"https:\/\/bugzilla.mozilla.org\/show_bug.cgi?id=1540913\">Bugzilla #1540913<\/a>.<\/li>\n<\/ul>\n<p>For more details on the progress of WebAssembly multithreading support, see https:\/\/github.com\/dotnet\/runtime\/issues\/68162.<\/p>\n<h2>Give feedback<\/h2>\n<p>We hope you enjoy this preview release of ASP.NET Core in .NET 7. Let us know what you think about these new improvements by filing issues on <a href=\"https:\/\/github.com\/dotnet\/aspnetcore\/issues\/new\">GitHub<\/a>.<\/p>\n<p>Thanks for trying out ASP.NET Core!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>.NET 7 Release Candidate 2 is now available! Check out what&#8217;s new in ASP.NET Core in this update.<\/p>\n","protected":false},"author":417,"featured_media":42740,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[685,197,7509,7251],"tags":[],"class_list":["post-42739","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dotnet","category-aspnet","category-aspnetcore","category-blazor"],"acf":[],"blog_post_summary":"<p>.NET 7 Release Candidate 2 is now available! Check out what&#8217;s new in ASP.NET Core in this update.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/42739","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/users\/417"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/comments?post=42739"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/42739\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media\/42740"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media?parent=42739"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/categories?post=42739"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/tags?post=42739"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}