{"id":9836,"date":"2017-06-28T10:02:15","date_gmt":"2017-06-28T17:02:15","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/webdev\/?p=9836"},"modified":"2017-06-28T10:02:15","modified_gmt":"2017-06-28T17:02:15","slug":"introducing-asp-net-core-2-0-preview-2","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/dotnet\/introducing-asp-net-core-2-0-preview-2\/","title":{"rendered":"Introducing ASP.NET Core 2.0 Preview 2"},"content":{"rendered":"<p>At Build 2017, we released an initial preview version of ASP.NET Core 2.0.\u00a0 Over the last two months we have incorporated your feedback and added a number of new features.\u00a0 We now have a Preview 2 version of the ASP.NET Core 2.0 framework and Visual Studio tools for you to try.\u00a0 In this post, we will review some of the new features in this preview release.<\/p>\n<h2>Update Visual Studio and install ASP.NET Core 2.0 Preview 2<\/h2>\n<p>If you don\u2019t already have the latest Visual Studio 2017 Preview version installed on your Windows system, download the latest from <a href=\"https:\/\/www.visualstudio.com\/vs\/preview\/\">https:\/\/www.visualstudio.com\/vs\/preview\/<\/a><\/p>\n<p>You can update an existing Visual Studio 2017 Preview installation using the Microsoft Visual Studio Installer application available on your start menu.\u00a0 Choose to update Visual Studio 2017 Preview and the latest Visual Studio 2017 Preview 3 patch (15.3 Preview 3) will be downloaded and applied to your installation. For Mac users, you should install the Visual Studio for Mac and update to the latest preview from the Beta channel.<\/p>\n<p>Next, download the latest <a href=\"https:\/\/www.microsoft.com\/net\/core\/preview\">.NET Core 2.0 SDK<\/a> and install it.\u00a0 This will give you an updated version of the .NET Core command-line tools and runtime.\u00a0 You can verify that you have the correct version installed by executing the following at the command-line:<\/p>\n<pre>dotnet \u2013-version<\/pre>\n<p>You should see the version \u201c2.0.0-preview2-006497\u201d reported, the current version of the 2.0 Preview 2 SDK.<\/p>\n<h2 id=\"spatemplates\">SPA Templates for Everyone!<\/h2>\n<p>When you start the updated Visual Studio 2017 Preview and create a new ASP.NET Core website with .NET Core, you will notice that the ASP.NET template chooser for ASP.NET Core 2.0 shows some extra templates:<\/p>\n<p><figure id=\"attachment_9846\" aria-labelledby=\"figcaption_attachment_9846\" class=\"wp-caption aligncenter\" ><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2017\/06\/AspNetCore2-2-1-1024x668-1.png\" alt=\"\" class=\"size-large wp-image-9846\" width=\"879\" height=\"573\" \/><figcaption id=\"figcaption_attachment_9846\" class=\"wp-caption-text\">New ASP.NET Core Templates<\/figcaption><\/figure><\/p>\n<p>The ASP.NET Core SPA templates for Angular and React are now available from Visual Studio.\u00a0 They\u2019re also available on the command-line as part of the standard installation of the .NET Core SDK.\u00a0 Of particular note, the Angular template has been updated to Angular 4.\u00a0 For more information about how to get started using the contents of the ASP.NET Core SPA templates, check the <a href=\"https:\/\/blogs.msdn.microsoft.com\/webdev\/2017\/02\/14\/building-single-page-applications-on-asp-net-core-with-javascriptservices\/\">article from Steve Sanderson<\/a> when the templates were initially made available.<\/p>\n<p>&nbsp;<\/p>\n<h2>ASP.NET Core 2 and .NET Framework<\/h2>\n<p>You can now choose to build your ASP.NET Core 2.0 applications with the .NET Framework by choosing the ASP.NET Core with .NET Framework template option in Visual Studio 2017.<\/p>\n<p><figure id=\"attachment_9855\" aria-labelledby=\"figcaption_attachment_9855\" class=\"wp-caption aligncenter\" ><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2017\/06\/AspNetCore2-3-1024x472-1.png\" alt=\"\" class=\"size-large wp-image-9855\" width=\"879\" height=\"405\" \/><figcaption id=\"figcaption_attachment_9855\" class=\"wp-caption-text\">Start a New ASP.NET Core Project with .NET Framework<\/figcaption><\/figure><\/p>\n<h2>Kestrel Improvements<\/h2>\n<p>We\u2019ve added a number of server constraint configuration options to the Kestrel server through the <a href=\"https:\/\/github.com\/aspnet\/KestrelHttpServer\/blob\/ea2f1033d389dc9cd89b7c3b4b28f920ec121ed9\/src\/Microsoft.AspNetCore.Server.Kestrel.Core\/KestrelServerOptions.cs#L47\">KestrelServerOptions class\u2019s new Limits property<\/a>.\u00a0 You can now <a href=\"https:\/\/github.com\/aspnet\/KestrelHttpServer\/blob\/rel\/2.0.0-preview2\/src\/Microsoft.AspNetCore.Server.Kestrel.Core\/KestrelServerLimits.cs\">add limits<\/a> for the following:<\/p>\n<ul>\n<li>Maximum Client Connections<\/li>\n<li>Maximum Request Body Size<\/li>\n<li>Maximum Request Body Data Rate<\/li>\n<\/ul>\n<h3>Maximum client connections<\/h3>\n<p>The maximum number of concurrent open HTTP\/S connections can be set for the entire application with the following code:<\/p>\n<pre>.UseKestrel(options =&gt;\n{\n\u00a0\u00a0\u00a0 options.Limits.MaxConcurrentConnections = 100;\n\u00a0\u00a0\u00a0 options.Limits.MaxConcurrentUpgradedConnections = 100;<\/pre>\n<p>Note how there are two limits. Once a connection is upgraded from HTTP to another protocol (e.g. on a WebSockets request), it\u2019s not counted against the limit anymore since upgraded connections have their own limit.<\/p>\n<h3>Maximum request body size<\/h3>\n<p>To configure the default constraint for the entire application:<\/p>\n<pre>.UseKestrel(options =&gt;\n{\n\u00a0\u00a0\u00a0 options.Limits.MaxRequestBodySize = 10 * 1024;\n\n<\/pre>\n<p>This will affect every request, unless it\u2019s overridden on a specific request:<\/p>\n<pre>app.Run(async context =&gt;\n{\n\u00a0\u00a0\u00a0 context.Features.Get&lt;IHttpMaxRequestBodySizeFeature&gt;().MaxRequestBodySize = 10 * 1024;<\/pre>\n<p>&nbsp;<\/p>\n<p>You can only configure the limit on a request if the application hasn\u2019t started reading yet, otherwise an exception is thrown. There\u2019s an IsReadOnly property in the feature that tells you if the request body is in read-only state, meaning it\u2019s too late to configure the limit.<\/p>\n<h3>Minimum request body data rate<\/h3>\n<p>To configure a default minimum request rate:<\/p>\n<pre>.UseKestrel(options =&gt;\n{\n\u00a0\u00a0\u00a0 options.Limits.RequestBodyMinimumDataRate = \n        new MinimumDataRate(rate: 100, gracePeriod: TimeSpan.FromSeconds(10));\n\n<\/pre>\n<p>To configure per-request:<\/p>\n<pre>app.Run(async context =&gt;\n{\n\u00a0\u00a0\u00a0 context.Features.Get&lt;IHttpRequestBodyMinimumDataRateFeature&gt;().MinimumDataRate = \n        new MinimumDataRate(rate: 100, gracePeriod: TimeSpan.FromSeconds(10));\n\n<\/pre>\n<p>The way the rate works is as follows: Kestrel will check every second if data is coming in at the specified rate in bytes\/second. If the rate drops below the minimum, the connection is timed out. The grace period is the amount of time that Kestrel will give the client to get it\u2019s send rate up to the minimum, so the rate is not checked during that time. This is to avoid dropping connections that are initially sending data at a slow rate due to TCP slow start.<\/p>\n<h2>Razor Support for C# 7.1<\/h2>\n<p>The Razor engine has been updated to work with the new Roslyn compiler and that includes support for C# 7.1 features like <a href=\"https:\/\/github.com\/dotnet\/csharplang\">Default Expressions<\/a>, <a href=\"https:\/\/github.com\/dotnet\/csharplang\/blob\/master\/proposals\/csharp-7.1\/infer-tuple-names.md\">Inferred Tuple Names<\/a>, and <a href=\"https:\/\/github.com\/dotnet\/csharplang\">Pattern-Matching with Generics<\/a>.\u00a0 To use C #7.1 features in your project add the following property in your project file and then reload the solution:<\/p>\n<pre>&lt;LangVersion&gt;latest&lt;\/LangVersion&gt;<\/pre>\n<p>C# 7.1 is itself in a preview state, and you can review the language specification for <a href=\"https:\/\/github.com\/dotnet\/roslyn\/blob\/master\/docs\/Language%20Feature%20Status.md\">these features on their GitHub repository<\/a>.<\/p>\n<h2>Enhanced HTTP Header Support for Range, ETags, and LastUpdate<\/h2>\n<p>When using MVC to transmit a FileStreamResult or a FileContentResult, you now have the option to set an ETag or a LastModified date on the content you wish to transmit.\u00a0 You can set these values on the returned content with code similar to the following:<\/p>\n<pre>var data = Encoding.UTF8.GetBytes(\"This is a sample text from a binary array\");\nvar entityTag = new EntityTagHeaderValue(\"\"MyCalculatedEtagValue\"\");\nreturn File(data, \"text\/plain\", \"downloadName.txt\", lastModified: DateTime.UtcNow.AddSeconds(-5), entityTag: entityTag);<\/pre>\n<p>&nbsp;<\/p>\n<p>The file returned to your visitors will be decorated with the appropriate HTTP headers for the ETag and Last Modified values.<\/p>\n<p>If an application visitor requests content with a <a href=\"https:\/\/en.wikipedia.org\/wiki\/List_of_HTTP_header_fields#range-request-header\">Range Request header<\/a>, ASP.NET will recognize that and handle that header. If the requested content can be partially delivered, ASP.NET will appropriately skip and return just the requested set of bytes.\u00a0 You do not need to write any special handlers into your methods to adapt or handle this feature, it is handled by the framework for you.<\/p>\n<h2>New Page Filters for Razor Pages<\/h2>\n<p>Page filters (IPageFilter, IAsyncPageFilter) allow you to run code before and after a page handler is executed, much in the same way that action filters let your run code before and after an action method is executed. Page filters can also influence which page handler gets executed or to run initialization code before model binding occurs. In Preview 2 you can add a page filter globally or using an app model convention. For preview 2 you can\u2019t apply filters using attributes, but we expect this <a href=\"https:\/\/github.com\/aspnet\/Mvc\/issues\/6334\">support to come later<\/a>.<\/p>\n<h2>Azure App Service Support<\/h2>\n<p>The Preview 2 version of ASP.NET Core 2.0 can be deployed to Azure App Service with no changes needed.\u00a0 Azure Data Centers are being rolled out today with completion scheduled for June 30th. You can track progress of the roll out on this <a href=\"https:\/\/github.com\/Azure\/app-service-announcements\/issues\/14\">Azure App Service Announcements issue<\/a>.<\/p>\n<h2>Postponed features<\/h2>\n<p>Some features available in Preview 1 have been pulled out of the ASP.NET Core 2.0 release to give them more time to bake. We still plan to do these features, but for now they have been removed from Preview 2. These features are:<\/p>\n<ul>\n<li>NET Core Identity as a Service, including the support for issue identity and access tokens using OpenID Connect and OAuth 2.0<\/li>\n<li>Default configuration schema for configuring HTTPS, certificates and authentication (you can still configure logging by default).<\/li>\n<\/ul>\n<h2>Summary<\/h2>\n<p>This preview release delivers some of the promised features of the ASP.NET Core 2.0 framework, and we hope that you try them out.\u00a0 You can find a complete set of release notes in the <a href=\"https:\/\/github.com\/aspnet\/Home\/releases\/tag\/2.0.0-preview2\">Home repository on GitHub<\/a> with links to the feature issues and pull-requests that completed those features.\u00a0 What do you think of the update to ASP.NET Core 2.0?\u00a0 Let us know in the comments below.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>At Build 2017, we released an initial preview version of ASP.NET Core 2.0.\u00a0 Over the last two months we have incorporated your feedback and added a number of new features.\u00a0 We now have a Preview 2 version of the ASP.NET Core 2.0 framework and Visual Studio tools for you to try.\u00a0 In this post, we [&hellip;]<\/p>\n","protected":false},"author":405,"featured_media":58792,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[197,7509],"tags":[30,7265],"class_list":["post-9836","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-aspnet","category-aspnetcore","tag-announcement","tag-announcements"],"acf":[],"blog_post_summary":"<p>At Build 2017, we released an initial preview version of ASP.NET Core 2.0.\u00a0 Over the last two months we have incorporated your feedback and added a number of new features.\u00a0 We now have a Preview 2 version of the ASP.NET Core 2.0 framework and Visual Studio tools for you to try.\u00a0 In this post, we [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/9836","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\/405"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/comments?post=9836"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/9836\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media\/58792"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media?parent=9836"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/categories?post=9836"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/tags?post=9836"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}