日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > asp.net >内容正文

asp.net

ASP.NET Core 3.0预览版体验

發布時間:2023/12/4 asp.net 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ASP.NET Core 3.0预览版体验 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

目前.NET Core 3.0的版本為.NET Core 3.0 Preview 3,對應ASP.NET Core 3.0 Preview 3。

ASP.NET Core 3.0 之后將不再支持.NET Framework,只運行在.NET Core 上面。

ASP.NET Core 3.0 現在已經出到了第三個預覽版,增加和改進了很多功能。

環境準備:

下載最新.NET Core 3.0?Preview 3 SDK,?https://dotnet.microsoft.com/download/dotnet-core/3.0。

ASP.NET Core 3.0 需要VS 2019開發,或者使用VS Code,Visual Studio for Mac version 8.0 or later。

Visual Studio 2019 將會在4月2日推出正式版。

下面大致列舉一些功能:

Json.NET 不在內置在框架內

如果要將Json.NET支持添加回ASP.NET Core 3.0項目:

  • 首先將包引用添加到Microsoft.AspNetCore.Mvc.NewtonsoftJson

  • 更新ConfigureServices方法以添加AddNewtonsoftJson()。

services.AddMvc()
.AddNewtonsoftJson();

HostBuilder 替換掉WebHostBuilder

public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}

public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder
=>
{
webBuilder.UseStartup
<Startup>();
});
}

UseRouting 中間件的增加

示例代碼:

app.UseRouting(routes =>
{
routes.MapGet(
"/hello", context =>
{
return context.Response.WriteAsync("Hi there! linezero");
});
});

同時還增加?MapHealthChecks及RequireHost 等功能,看示例:

app.UseRouting(routes =>
{
routes.MapGet(
"/", context => context.Response.WriteAsync("Hi linezero!"))
.RequireHost(
"linezero.com");
routes.MapGet(context
=> context.Response.WriteAsync("Hi zero!"))
.RequireHost(
"zero.com");

routes.MapHealthChecks(
"/healthz").RequireHost("*:8080");
});

Razor Components?

razor 組件支持,下面實際看看這個功能點。

dotnet new razorcomponents -o myweb

cd myweb

dotnet run

運行起來如下圖:

對應組件代碼Counter.razor :

@page "/counter"

<h1>Counter</h1>
<p>LineZero</p>

<p>Current count: @currentCount</p>

<button class="btn btn-primary" οnclick="@IncrementCount">Click me</button>

@functions {
int currentCount = 0;

void IncrementCount()
{
currentCount
++;
}
}

?你可以直接將組件添加到主頁或其他頁面,例如放到主頁Index.razor:

@page "/"

<h1>Hello, world!</h1>

Welcome to your
new app.LineZero

<Counter />

?還可以使用?[Parameter] int IncrementSize { get; set; } = 1; 來設置參數:

@functions {
int currentCount = 0;

[Parameter]
int IncrementSize { get; set; } = 1;

void IncrementCount()
{
currentCount
+=IncrementSize;
}
}

這樣可以做到每個頁面設置不同的大小,增加不同數量。

如:

@page "/"

<h1>Hello, world!</h1>

Welcome to your
new app.LineZero

<Counter IncrementSize="6"/>

下圖描述了Razor的一些原理。

另外,Blazor是一個實驗性單頁面應用程序框架,它使用基于WebAssembly的.NET運行時直接在瀏覽器中運行Razor Components。

在Blazor應用程序中,Razor組件的UI更新都直接應用于DOM。

運行時編譯

從.NET Core 3.0中的ASP.NET Core共享框架中刪除了對運行時編譯的支持,現在可以通過向應用程序添加軟件包來啟用它。

要啟用運行時編譯:

  • 添加對Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation的包引用

    <PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="3.0.0-preview3-19153-02" />
  • 在Startup.ConfigureServices加入方法AddRazorRuntimeCompilation

    services.AddMvc().AddRazorRuntimeCompilation();
  • Worker Service模板

    此模板旨在作為運行長時間運行的后臺進程的起點,例如您可以作為Windows服務或Linux守護程序運行。

    單頁面應用程序模板的身份驗證

    由IdentityServer在后臺提供支持

    dotnet new angular -au Individual

    dotnet run

    最終運行起來,可以進行登錄注冊,及對API 的保護。

    更多可以查看官方文檔:https://docs.microsoft.com/en-us/aspnet/core/security/authentication/identity-api-authorization?view=aspnetcore-3.0

    gRPC服務模板

    會生成兩個項目,一個在ASP.NET Core中托管的gRPC服務,以及一個用它來測試它的控制臺應用程序。

    這是gRPC for ASP.NET Core的第一次公開預覽,并沒有實現gRPC的所有功能。對應開源項目: https://github.com/grpc/grpc-dotnet

    gRPC 簡單介紹可以參照之前文章:http://www.cnblogs.com/linezero/p/grpc.html? 及?https://www.cnblogs.com/linezero/p/grpcnetcore.html

    原文地址:https://www.cnblogs.com/linezero/p/aspnetcore3preview.html

    .NET社區新聞,深度好文,歡迎訪問公眾號文章匯總 http://www.csharpkit.com


    總結

    以上是生活随笔為你收集整理的ASP.NET Core 3.0预览版体验的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。