從 ASP.NET Core 2.2 移轉到 3.0
作者:Scott Addie 與 Rick Anderson
Author: Scott Addie and
本文說明如何將現有的 ASP.NET Core 2.2 專案更新為 ASP.NET Core 3.0。 建立新的 ASP.NET Core 3.0 專案可能有助於:
This paper explains how to update the existing ASP.NET Core 2.2 project to ASP.NET Core 3.0. The creation of a new ASP.NET Core 3.0 project may help:
- 與 ASP.NET Core 2.2 程式碼比較。
- 將相關變更複製到您的 ASP.NET Core 3.0 專案。
- Visual Studio 2019 和 ASP.NET 與 Web 開發工作負載
- .NET Core 3.0 SDK
如果您的解決方案依賴 global.json 檔案而以特定的 .NET Core SDK 版本為目標,請將其 屬性更新為您電腦上安裝的 3.0 版:
If your solution is based on global.json with the specific.NET Core SDK version, please update its properties to the 3.0 version installed on your computer:
ASP.NET Core 3.0 及更新版本只能在 .NET Core 上執行。 請將 目標 Framework Moniker (TFM) 設定為 :
ASP.NET Core 3.0 and updates can only be implemented on.NET Core. Set the target :
不會針對 ASP.NET Core 3.0 產生大量的 NuGet 套件。 這類套件參考應該從您的專案檔中移除。 針對 ASP.NET Core 2.2 Web 應用程式,請考慮下列專案檔:
Do not generate a large number of NuGet packages for ASP.NET Core 3.0. Reference packages of this type should be removed from your project file. For ASP.NET Core 2.2 Web applications, consider the following project files:
ASP.NET Core 3.0 的更新專案檔:
Update project file for ASP.NET Core 3.0:
已更新的 ASP.NET Core 3.0 專案檔:
Updated ASP.NET Core 3.0 project file:
在 :
In:
- 將 TFM 更新至
- 移除 元素。 如需詳細資訊,請參閱本文件中的內含式裝載模型。
在 :
In:
- 會遭到移除。 如需詳細資訊,請參閱本文件中的架構參考。
- 會遭到移除,且在下列套件清單中不再產生。
若要查看不再產生的完整套件清單,請選取下列展開清單:
To view the full list of non-generated packages, select the following extension list:
按一下以展開不再產生的套件清單
- Microsoft.AspNetCore
- Microsoft.AspNetCore.All
- Microsoft.AspNetCore.App
- Microsoft.AspNetCore.Antiforgery
- Microsoft.AspNetCore.Authentication
- Microsoft.AspNetCore.Authentication.Abstractions
- Microsoft.AspNetCore.Authentication.Cookies
- Microsoft.AspNetCore.Authentication.Core
- Microsoft.AspNetCore.Authentication.OAuth
- Microsoft.AspNetCore.Authorization.Policy
- Microsoft.AspNetCore.CookiePolicy
- Microsoft.AspNetCore.Cors
- Microsoft.AspNetCore.Diagnostics
- Microsoft.AspNetCore.Diagnostics.HealthChecks
- Microsoft.AspNetCore.HostFiltering
- Microsoft.AspNetCore.Hosting
- Microsoft.AspNetCore.Hosting.Abstractions
- Microsoft.AspNetCore.Hosting.Server.Abstractions
- Microsoft.AspNetCore.Http
- Microsoft.AspNetCore.Http.Abstractions
- Microsoft.AspNetCore.Http.Connections
- Microsoft.AspNetCore.Http.Extensions
- Microsoft.AspNetCore.HttpOverrides
- Microsoft.AspNetCore.HttpsPolicy
- Microsoft.AspNetCore.Identity
- Microsoft.AspNetCore.Localization
- Microsoft.AspNetCore.Localization.Routing
- Microsoft.AspNetCore.Mvc
- Microsoft.AspNetCore.Mvc.Abstractions
- Microsoft.AspNetCore.Mvc.Analyzers
- Microsoft.AspNetCore.Mvc.ApiExplorer
- Microsoft.AspNetCore.Mvc.Api.Analyzers
- Microsoft.AspNetCore.Mvc.Core
- Microsoft.AspNetCore.Mvc.Cors
- Microsoft.AspNetCore.Mvc.DataAnnotations
- Microsoft.AspNetCore.Mvc.Formatters.Json
- Microsoft.AspNetCore.Mvc.Formatters.Xml
- Microsoft.AspNetCore.Mvc.Localization
- Microsoft.AspNetCore.Mvc.Razor
- Microsoft.AspNetCore.Mvc.Razor.ViewCompilation
- Microsoft.AspNetCore.Mvc.RazorPages
- Microsoft.AspNetCore.Mvc.TagHelpers
- Microsoft.AspNetCore.Mvc.ViewFeatures
- Microsoft.AspNetCore.Razor
- Microsoft.AspNetCore.Razor.Runtime
- Microsoft.AspNetCore.Razor.Design
- Microsoft.AspNetCore.ResponseCaching
- Microsoft.AspNetCore.ResponseCaching.Abstractions
- Microsoft.AspNetCore.ResponseCompression
- Microsoft.AspNetCore.Rewrite
- Microsoft.AspNetCore.Routing
- Microsoft.AspNetCore.Routing.Abstractions
- Microsoft.AspNetCore.Server.HttpSys
- Microsoft.AspNetCore.Server.IIS
- Microsoft.AspNetCore.Server.IISIntegration
- Microsoft.AspNetCore.Server.Kestrel
- Microsoft.AspNetCore.Server.Kestrel.Core
- Microsoft.AspNetCore.Server.Kestrel.Https
- Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions
- Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets
- Microsoft.AspNetCore.Session
- Microsoft.AspNetCore.SignalR
- Microsoft.AspNetCore.SignalR.Core
- Microsoft.AspNetCore.StaticFiles
- Microsoft.AspNetCore.WebSockets
- Microsoft.AspNetCore.WebUtilities
- Microsoft.Net.Http.Headers
透過上述其中一個套件提供的 ASP.NET Core 功能,可作為 共用架構的一部分。 共用架構是一組安裝在電腦上的組建 (.dll 檔案),並包含執行階段元件和目標套件。 如需詳細資訊,請參閱共用的架構 \(英文\)。 The ASP.NET Core feature provided through one of the above packages can be used as part of a common architecture. shared structure is a set of configurations installed on a computer (.dll file) and contains an active session widget and target package. For more detailed information, please refer to . 以 SDK 為目標的專案會隱含地參考 架構。 Project with SDK as its target will be consulted implicitly. 這些專案不需要其他參考: These projects do not require any other reference: 以 或 SDK 為目標的專案,應該將明確 新增至 : A project with a target or SDK should be clearly added to: 使用相依於 ASP.NET Core 共用架構之套件的主控台應用程式架構相依組建,可能會產生下列執行階段錯誤: Using the configuration of the master control application based on a common set of ASP.NET Core
是包含 ASP.NET Core 執行階段的共用架構,且只存在於 Docker 映像上。 3.0 SDK 會使用 ASP.NET Core 來減少架構相依組建的大小,方法是不包含共用架構中可用的程式庫複本。 這是最多 18 MB 的潛在節省,但是需要 ASP.NET Core 執行階段存在/安裝才能執行應用程式。 It is a shared structure that contains the ASP.NET Core stage and only exists on the Docker image. 3.0 SDK uses ASP.NET Core to reduce the size of the structure by not including a copy of the program library available in the common frame. This is a potential economy of up to 18 MB, but requires the ASP.NET Core stage to exist/installation to run the application. 若要判斷應用程式在 ASP.NET Core 共用架構上是否具有相依性 (直接或間接),請檢查應用程式建置/發佈期間產生的 檔案。 下列 JSON 檔案顯示與 ASP.NET Core 共用架構的相依性: To determine whether the application is dependent (directly or intermittently) on the ASP.NET Core common structure, check the files generated during the build/ release period of the application. The following JSON files show the dependencies of the ASP.NET Core common setup: 如果您的應用程式使用 Docker,請使用包含 ASP.NET Core 3.0 的基礎映像。 例如: 。 If your application uses Docker, use a base image containing ASP.NET Core 3.0. For example: ASP.NET Core 3.0 會移除先前屬於 套件參考的一些組件。 若要將已移除的組件視覺化,請比較兩個共用架構資料夾。 例如,比較 2.2.7 版和 3.0.0 版: ASP.NET Core 3.0 removes some of the components that were previously part of the package reference. To visualize the removed components, please compare two shared frame folders. For example, compare version 2.2.7 with version 3.0.0:
若要繼續使用已移除組件所提供的功能,請參考對應套件的 3.0 版本: To continue using the functions provided by the removed component, refer to version 3.0 of the corresponding package: 具有個別使用者帳戶的範本產生 Web 應用程式需要新增下列套件: The following new packages are required for the web application to generate a template with : 如需參考資料庫提供者特定套件的詳細資訊,請參閱資料庫提供者。 For more detailed information on specific packages from database providers, see . Identity UI 針對 Identity UI 的支援可藉由參考 Microsoft.AspNetCore.Identity.UI 套件來新增。 Support for IdentityUI may be added by reference to https://ahref=https://www.nuget.org/packages/soft.AspNetCore.Identity.UI'data-linktype="external" Microsoft.AspNetCore.Identity.UI SPA 服務 SPA Service 驗證:支援第三方驗證流程是以 NuGet 套件的形式提供: Authentication: The support for third-party verification process is provided in the form of a NuGet package: 針對 的格式化和內容交涉支援:Microsoft.AspNet.WebApi.Client NuGet 套件使用例如 和 的 API 提供對 的有用擴充性。 不過,此套件相依於 ,而非 。 舉例來說,這表示會略過由 () 指定的序列化屬性名稱。 有一個較新的 NuGet 套件包含類似的擴充方法,但是使用 :System.Net.Http.Json。 Support for formatting and content negotiation: NuGet sets of APIs, for example. However, this package is based on rather than on the serialized names specified by () "data-linktype". There is a new NuGet package that contains similar enrichment methods, but uses: Razor 執行階段編譯:支援 Razor 檢視和頁面的執行階段編譯,現在屬於 Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation。 Razor Executive Session Development: Supports the Razor View and Page Implementation Phase Development, now belonging to Microsoft. AspNetCore. Mvc. Razor. Runtecompilation. MVC (Json.NET) 支援:支援透過 使用 MVC 現在屬於 。 MVC (Json.NET) Support: Support for the use of MVC through . 下圖顯示 ASP.NET Core 2.2 Razor Pages Web 應用程式中已刪除和已變更的行: The following graph shows the deleted and changed lines in the ASP.NET Core 2.2 Razor Pages Web application:
在上圖中,已刪除的程式碼會以紅色顯示。 已刪除的程式碼不會顯示 cookie 選項程式碼,在比較檔案之前已刪除。 In the above graph, the deleted code is shown in red. The deleted code does not show the cookie option and has been deleted before comparing the file. 下圖顯示 ASP.NET Core 3.0 Razor Pages Web 應用程式中已新增和已變更的行: The following graph shows new and changed lines in ASP.NET Core 3.0 Razor Pages Web applications:
在上圖中,新增的程式碼會以綠色顯示。 如需下列變更的詳細資訊: In the above graph, the new code is shown in green. The details of the following changes are required: 以 為目標的專案,會隱含地參考先前隨附於 Microsoft.AspNetCore.Mvc.Analyzers 套件的分析器。 不需要其他參考就能啟用這些參考。 The targeted project will implicitly refer to the analyzer previously attached to . These references can be accessed without other references. 如果您的應用程式使用先前隨附於 Microsoft.AspNetCore.Mvc.Api.Analyzers 套件的 API 分析器,請編輯您的專案檔以參考隨附於 .NET Core Web SDK 的分析器: If your application uses Microsoft.AspNetCore.Mvc. Api. Analyzers package , please edit your ad hoc file for reference to the analyst.NETCoreWeb SDK: 為 MVC 提供 UI 元件的 Razor 類別庫專案,必須在專案檔中設定 屬性: The Razor library project that provides UI widgets for MVC must configure properties in the project file: 專案在 ASP.NET Core 3.0 或更新版本中預設為內含式裝載模型。 如果專案檔中 屬性的值為 ,您可以選擇性地將其移除。 The project is preset in ASP.NET Core 3.0 or the updated version as . If the property value in the project file is the value, you can choose to remove it. 將 Kestrel 組態移轉至由 () 提供的 Web 主機建立器: Move the Kestrel configuration to Web Host Builder: 如果應用程式以手動方式透過 建立主機,而不是使用 ,請在 Web 主機建立器上呼叫 : If the application creates the host manually instead of using it, call on the web host builder: 連線配接器 () 已從 Kestrel 中移除。 以連線中介軟體取代連線配接器。 連線中介軟體類似於 ASP.NET Core 管線中的 HTTP 中介軟體,但是適用於較低層級的連線。 HTTPS 和連線記錄: Connector () has been removed from Kestrel. The connection broker software is replaced by the connection broker software. The connection broker software is similar to the HTTP intermediary software in the ASP.NET Core line, but is suitable for lower-level connections. HTTPS and connection logs: 如需詳細資訊,請參閱 Kestrel 文章中 ListenOptions.Protocols 一節中的 TlsFilterConnectionHandler 範例。 For more detailed information, please refer to ListenOptions.Protocols section Kestrel 傳輸層已公開為 中的公用介面。 作為這些更新的一部分: The Kestrel transfer layer has been made public as a public interface. As part of these updates: 如需詳細資訊,請參閱下列 GitHub 資源: For more information, see the following GitHub resources: 針對以舊版 ASP.NET Core 為目標的應用程式: An application aimed at the old version of ASP.NET Core: 這引起了一些關於標頭和尾端之間模棱兩可的顧慮,因此在 3.0 中尾端已移至新的集合 ()。 This gives rise to a number of ambiguous concerns between the cap and the end and has been moved to a new assembly (at the middle end of 3.0). HTTP/2 要求尾端如下: HTTP/2 requires the following endpoint: 有新的要求擴充方法來存取這些尾端。 使用 HTTP/1.1,尾端會在要求本文讀取至結尾之後提供。 There are new requirements to expand access to these tails. Using HTTP/1.1, the end will be provided after the request has been read to the end. 針對 3.0 版本,有下列 方法可供使用: For version 3.0, the following methods are available: 如需詳細資訊,請參閱將要求尾端放在個別集合中 (dotnet/AspNetCore #10410)。 For more information, please refer to . 啟用或停用同步 I/O API,例如 、 和 。 這些 API 是導致應用程式當機的執行緒耗盡來源。 在 3.0 中,預設會停用 。 如需詳細資訊,請參閱 Kestrel文章中的同步 I/O 一節。 Enables or disables synchronisation I/ O API, e. g., and these APIs are the sources that cause the application to run out of energy. In 3.0, the default will be deactivated. See Kestrel's article Synchronization I/ O section . 如果需要同步 I/O,可以在所使用的伺服器上設定 選項來啟用 (呼叫 時,例如若使用 Kestrel)。 請注意,伺服器 (Kestrel、HttpSys、TestServer 等等) 都有不會影響其他伺服器的 選項。 您可以使用 選項,針對每個要求啟用所有伺服器的同步 I/O: If you want to sync I/O, set the options to be enabled on the server you use (calling, e. g. if Kestrel is used). Note that all servers (Kestrel, HttpSys, TestServer, etc.) have options that do not affect other servers. You can use the options to synchronize every request to enable all servers I/O: 如果您在 Dispose 中呼叫同步 API 的 TextWriter 實作或其他資料流發生問題,請改為呼叫新的 DisposeAsync API。 If you call API at , call API at , please refer to a new
如需詳細資訊,請參閱 [公告] 在所有伺服器中停用 AllowSynchronousIO (dotnet/AspNetCore #7644)。 For more information, please refer to on all servers. Newtonsoft.Json、XmlSerializer 和 DataContractSerializer 型輸出格式器僅支援同步序列化。 為了允許這些格式器使用伺服器的 AllowSynchronousIO 限制,MVC 會在寫入磁碟之前,緩衝這些格式器的輸出。 由於緩衝處理,MVC 會在使用這些格式器回應時包含 Content-Length 標頭。 ,
System.Text.Json 支援非同步序列化,因此 型格式器不會緩衝處理。 請考慮使用此格式器來改善效能。
若要停用緩衝處理,應用程式可以在其啟動程序中設定 SuppressOutputFormatterBuffering: To deactivate buffers, the application can set
請注意,如果未設定 ,這可能會導致應用程式擲回執行階段例外狀況。 Please note that, if not set, this may lead to application throwing back the phase exception. 在 ASP.NET Core 2.1 中,Microsoft.AspNetCore.Server.Kestrel.Https.dll 的內容已移至 Microsoft.AspNetCore.Server.Kestrel.Core.dll。 這是使用 屬性的非中斷性更新。 針對 3.0,空白 Microsoft.AspNetCore.Server.Kestrel.Https.dll 組件和 NuGet 套件已移除。 In ASP.NET Core 2.1, the contents of Microsoft.AspNetCore.Server.Kestrel.Https.dll have been moved to .AspNetCore.Server.Kestrel.Core.dll. This is a non-intermittal update using attributes. For 3.0, the blanks Microsoft.AspNetCore. Server.Kestrel.Htps.dll and the NuGet package have been removed. 參考 Microsoft.AspNetCore.Server.Kestrel.Https 的程式庫應該將 ASP.NET Core 相依性更新為 2.1 會更新版本。 See Microsoft. AspNetCore. Server. Kestrel. Https should update ASP.NET Cores to 2.1. 以 ASP.NET Core 2.1 或更新版本為目標的應用程式或程式庫,應該移除對 Microsoft.AspNetCore.Server.Kestrel.Https 套件的任何直接參考。 Applications or libraries targeting ASP.NET Core 2.1 or updated versions should remove any direct reference to packages. 在改善 ASP.NET Core 共用架構的過程中,Newtonsoft.Json (Json.NET) 已從 ASP.NET Core 共用架構移除。 In the process of , has been removed from the ASP.NET Core joint venture. 適用於 ASP.NET Core 的預設 JSON 序列化程式現在是 System.Text.Json,這是 .NET Core 3.0 中的新功能。 請考慮盡可能使用 。 它是高效能的,不需要額外的程式庫相依性。 不過,由於 是新功能,因此目前可能缺少您的應用程式所需的功能。 如需詳細資訊,請參閱如何從 Newtonsoft.Json 移轉至 System.Text.Json。 The default JSON sequencing program suitable for ASP.NET Core is now , which is a new feature in https://docs.microft. com/zh-tw/dotnet/site/stunaridation. However, since this function is new, it may currently lack the functionality required for your app. 安裝 Microsoft.AspNetCore.SignalR.Protocols.NewtonsoftJson NuGet 套件。 Install Microsoft. AspNetCore. SignalR. Protocols. NewtonsoftJson NuGet package. 在用戶端上,將 方法呼叫鏈結到 執行個體: On client, link the method to the executable: 在伺服器上,將 方法呼叫鏈結到 中的 方法呼叫: On the server, call method to link to method: Install . 更新 以呼叫 。 Update to call. 與新 MVC 服務註冊方法相容: Compatibility with the new MVC service register: 設定可以在對 的呼叫中設定: Settings can be set in the corresponding call: 注意:如果 方法無法使用,請確定您已安裝 套件。 常見錯誤是安裝 Newtonsoft.Json 套件,而不是 套件。 如需詳細資訊,請參閱新增 Newtonsoft.Json 型 JSON 格式支援。 For more information, please refer to . ASP.NET Core 3.0 會新增選項,以在 內註冊 MVC 案例。 ASP.NET Core 3.0 adds an option to register MVC cases. 有三個與 上 MVC 案例相關的新最上層擴充方法可供使用。 範本會使用這些新方法,而不是 。 不過, 會繼續以舊版的形式運作。 There are three new top-up scaling methods available in relation to the MVC case. Templates will use these new methods instead of using them. However, they will continue to operate in the old version. 下列範例會新增控制器和 API 相關功能的支援,但是不會新增檢視或頁面的支援。 API 範本會使用此程式碼: The following examples add support for controls and API-related functions, but do not add support for a view or page. The API template uses this code: 下列範例會新增控制器、API 相關功能和檢視的支援,但是不會新增頁面的支援。 Web 應用程式 (MVC) 範本會使用此程式碼: The following examples add support for controllers, API-related functions and views, but do not add support for pages. The Web Application (MVC) template uses this code: 下列範例會新增 Razor Pages 的支援和最低控制器支援。 Web 應用程式範本會使用此程式碼: The following examples add Razor Pages support and minimum controller support. The Web application template uses this code: 也可以合併新的方法。 下列範例相當於在 ASP.NET Core 2.2 中呼叫 : You can also merge new methods. The following examples are equivalent to those called in ASP.NET Core 2.2: 如果應用程式呼叫 或 ,請盡可能將應用程式移轉至端點路由。 為了改善與舊版 MVC 的端點路由相容性,我們已還原 ASP.NET Core 2.2 中所引進 URL 產生的一些變更。 如果您在 2.2 中使用端點路由時遇到問題,預期在 ASP.NET Core 3.0 中可改善,但是有以下例外狀況: If the application calls or is possible, move the application to . In order to improve compatibility with the end-point path of the old MVC, we have returned some of the changes introduced into URL in ASP.NET Core 2.2. If you have problems using the end-point path in 2.2, this is expected to be improved in ASP.NET Core 3.0, with the following exceptions: 端點路由支援與 相同的路由模式語法和路由模式撰寫功能。 端點路由支援 。 端點路由支援 、 和其他 MVC 路由屬性。 Peer path support for the same route syntax and route writing function. Peer path support. Peer path support, and other MVC route attributes. 對於大部分的應用程式,只有 需要變更。 For most applications, only changes are required. 一般建議: General recommendations: 加入 。 Accession. 如果應用程式呼叫 ,請在 前面放置 。 If the application calls, please place strong> in front of . 如果應用程式使用例如 或 的驗證/授權功能,請對 和 進行呼叫:後面, 和 ,但是在 前面: If the application uses a validation/ authorization function such as strong>, call to: strong> after , and before: 以 取代 或 。 Replace with %1 or %2. 如果應用程式使用 CORS 案例,例如 ,請在使用 CORS 的任何其他中介軟體前面放置對 的呼叫 (例如,在 、 和 前面放置 )。 If the application uses CORS case, for example, please place the call in front of any other intermedial software using CORS (e. g. place in front). 以 取代 ,並且針對 Microsoft.AspNetCore.Hosting 命名空間新增 陳述式。 Replaces with . 將 取代為 IHostApplicationLifetime (Microsoft.Extensions.Hosting 命名空間)。 將 取代為 Environments (Microsoft.Extensions.Hosting 命名空間)。 下列程式碼是一般 ASP.NET Core 2.2 應用程式中的 範例: The following codes are examples of generic ASP.NET Core 2.2 applications: 更新先前的 程式碼之後: Update the previous code: 警告 This function is EXPERIMENTAL. 對於大部分的應用程式,對 、 和 的呼叫必須在對 和 的呼叫之間出現才能生效。 For most applications, calls for, and between, applications must appear in order to be effective. 健康情況檢查會搭配一般主機使用端點路由。 在 中,使用端點 URL 或相對路徑在端點建立器上呼叫 : A health check combines a normal host with a peer path. In this, call on the peer builder using a peer URL or relative path: 健康情況檢查端點可以: The health check peer can: 如需詳細資訊,請參閱 ASP.NET Core 中的健康狀態檢查。 For more information, please refer to . 授權和 CORS 的支援會與中介軟體方法整合。 這可讓您在這些案例中使用相同的中介軟體和功能。 此版本中會提供更新的授權中介軟體,並增強 CORS 中介軟體,以便了解 MVC 控制器所使用的屬性。 Grant and CORS support is integrated with . This allows you to use the same intermediary software and functionality in these cases. This version will provide an updated licensing broker software and enhance the CRRS intermediary software to understand the properties used by the MVC controller. 以前 CORS 可能很難設定。 已提供中介軟體以在某些使用案例中使用,但是 MVC 篩選的目的是在不使用中介軟體的情況下,在其他使用案例中使用。 使用 ASP.NET Core 3.0 時,我們建議所有需要 CORS 的應用程式都搭配端點路由使用 CORS 中介軟體。 可以提供預設原則,而 和 屬性可以用來在必要時覆寫預設原則。 Former CORS may be difficult to configure. Intermediary software has been provided for use in some use cases, but MVC selections are intended to be used in other use cases where 在以下範例中: In the following examples: 在舊版 ASP.NET Core 中,已透過 屬性提供授權支援。 授權中介軟體無法使用。 在 ASP.NET Core 3.0 中,需要授權中介軟體。 建議您在 後面立即放置 ASP.NET Core 授權中介軟體 ()。 授權中介軟體也可以設定為具有預設原則,預設原則可以覆寫。 In the old version of ASP.NET Core, authorization support is provided through attributes. Licensing intermediary software is not available. In ASP.NET Corre 3.0, authorization intermediary software is required. It is recommended that you place the ASP.NET Corre Authority Intermediary software () immediately behind you. The licensing broker software can also be configured to have defaults, which can be overwritten. 在 ASP.NET Core 3.0 或更新版本中, 是在 中呼叫,且下列 需要已登入的使用者: In ASP.NET Core 3.0 or updated version, call in and require the following login users: 使用端點路由時,建議您不要設定 AuthorizeFilter 並改為依賴授權中介軟體。 如果應用程式在 MVC 中使用 作為全域篩選,建議您重構程式碼,以在對 的呼叫中提供原則。 When using the peer path, you are advised not to set
一開始設定為需要驗證,因此不需要額外的設定。 在下列範例中,MVC 端點會標示為 ,因此所有要求都必須根據 獲得授權。 不過,由於 ,所以 允許在沒有使用者登入應用程式的情況下存取: From the beginning, the settings are set to be verified, so no additional settings are required. In the following examples, the MVC endpoint will be marked, so all requirements must be authorized. However, since there is no user login application, access is allowed: 您也可以針對特定端點類別設定授權。 下列程式碼是轉換 MVC 應用程式的範例,將全域 設定為具有需要授權之特定原則的應用程式: You can also set permissions for specific endpoint categories. The following code is an example of converting a MVC application, setting the world as an application with specific principles that require authorization: 您也可以自訂原則。 設定為需要驗證: You can also customize the rules. Set to need verification: 或者,可以藉由設定 ,將所有端點設定為需要授權,而不需要 或 。 與 不同。 是由 或 觸發,而 是在未設定其他原則時觸發。 一開始設定為允許未經授權的要求。 Alternatively, you can set all endpoints to be authorized without needing or using configuration. Unlikely, they are triggered by or without other principles. They are initially set to allow unauthorised requirements. 下列範例與上述 範例相同,但是使用 來一律要求所有端點上的驗證,除非已指定 : The following examples are the same as the above examples, but are used to require all peer verifications unless specified: 中介軟體的授權可在沒有架構具備任何特定授權知識的情況下運作。 例如,健康情況檢查沒有特定授權知識,但是健康情況檢查可以有中介軟體所套用的可設定授權原則。 Intermediary software may operate without having any specific licensing knowledge in place. For example, does not have specific licensing knowledge, but health tests can have set-up licensing principles for intermediary software. 此外,每個端點都可以自訂其授權需求。 在下列範例中, 會處理具有 的授權,但是 健康情況檢查端點需要 使用者: In addition, each endpoint can customize its authorization requirements. In the following examples, the authorization is processed, but the health check endpoint needs the user: 某些案例會實作保護。 如果因為遺漏中介軟體而略過授權或 CORS 原則,則端點中介軟體會擲回例外狀況。 分析器支援提供有關設定錯誤的其他意見反應正在進行中。 If authorization or CORS principles are omitted due to the omission of an intermediary software, the peer broker software returns the exception. The analyst supports other reactions that provide wrong settings. 如果應用程式使用自訂授權處理常式,端點路由會將不同的資源類型傳遞給 MVC 以外的處理常式。 預期授權處理常式內容資源是 AuthorizationFilterContext 類型 (MVC 篩選提供的資源類型) 的處理常式,必須更新才能處理 RouteEndpoint 類型的資源 (端點路由給予授權處理常式的資源類型)。 If the app uses custom , MVC 仍會使用 資源,因此如果應用程式使用 MVC 授權篩選以及端點路由授權,可能需要處理這兩種類型的資源。 MVC still uses resources, so if the application uses MVC licensing and peer path authorization, both types of resources may need to be handled. SignalR 中樞的對應現在會在 內進行。 SignalR’s response will now be internalized. 使用 對應每個中樞。 如同舊版,會明確列出每個中樞。 Use the medium for each. As in the old version, each medium is clearly listed. 在下列範例中,會新增 SignalR 中樞的支援: Support from SignalR will be added in the following examples: 有一個新選項可控制來自用戶端的訊息大小限制。 例如,在 中: There is one new option to control the message size limit from the client. For example: 在 ASP.NET Core 2.2 中,您可以設定 ,有效地控制訊息大小上限。 在 ASP.NET Core 3.0 中,該選項現在只會控制在觀察到 backpressure 之前的大小上限。 In ASP.NET Core 2.2, you can set an effective limit on the size of the message. In ASP.NET Core 3.0, the option will now be limited to the size limit before observing backpressure. ASP.NET Core SignalR 伺服器端組件現在會隨 .NET Core SDK 一起安裝。 如需詳細資訊,請參閱本文件中的移除過時的套件參考。 The ASP.NET Core SignalR server component will now be installed with.NET Core SDK. For more information, please refer to in this document. 控制器的對應現在會在 內進行。 The controller's response will now be inside. 如果應用程式使用屬性路由,請新增 。 由於在 ASP.NET Core 3.0 或更新版本中,路由包含許多架構的支援,因此新增屬性路由控制器是選擇性的。 If the application uses a attribute route, add it. Since in ASP.NET Core 3.0 or an updated version, it contains support from many structures, so adding a attribute route controller is optional. 取代下列項目: Replace the following items with the following: 由於路由現在包含不僅僅是 MVC 的支援,因此術語已變更,更清楚說明這些方法的用途。 // 之類的傳統路由會依新增的順序套用。 先放置更具體的路由 (例如區域路由)。 As routers now contain more than just support from MVC, the language has changed to provide a clearer picture of the use of these methods. Traditional routers such as / / / will be applied according to the new order. 在以下範例中: In the following examples: 在 ASP.NET Core 3.0 中,ASP.NET Core MVC 會從控制器動作名稱中移除 尾碼。 路由和連結產生都會受到這個新預設值的影響。 例如: In ASP.NET Core 3.0, ASP.NET Core MVC removes tails from the controller action name. Routes and links generation are affected by this new default, for example: ASP.NET Core 3.0 之前: Before ASP.NET Core 3.0: 上述動作可以在 Products/ListAsync 路由存取。 These actions can be accessed by route Products/ListAsync. 產生連結需要指定 尾碼。 例如: Generate links requires the specification of a tail. For example: 在 ASP.NET Core 3.0 中: In ASP.NET Core 3.0: 上述動作可以在 Products/List 路由存取。 These actions can be accessed by Products/List. 連結產生不需要指定 尾碼。 例如: Link generation does not require the specification of a tail. For example: 這項變更不會影響使用 屬性指定的名稱。 使用 中的下列程式碼可以停用預設行為: This change will not affect the use of attributes . The following code in use can disable the default actions: 連結產生有一些差異 (例如,使用 和類似 API)。 包括: There are some differences in connection generation (e. g. use and similar API). These include: 對應 Razor Pages 現在會在 內進行。 Reaction to Razor Pages will now take place inside. 如果應用程式使用 Razor Pages,請新增 。 由於端點路由包含許多架構的支援,因此新增 Razor Pages 現在是選擇性的。 If the application uses Razor Pages, add it. Since the peer path contains support from many structures, adding Razor Pages is now optional. 在下列 方法中, 會新增 Razor Pages 的支援: The Razor Pages support is added to the following methods: 透過 或 在 ASP.NET Core 3.0 中使用 MVC,需要在 內明確加入。 這是必要的,因為 MVC 必須知道它是否可以在初始化期間依賴授權和 CORS 中介軟體。 如果應用程式嘗試使用不支援的設定,則會提供分析器來警告。 This is necessary because MVC must know whether it can rely on the licensing and CORS intermediary software during the initialization period. If the application tries to use unsupported settings, an analyser is provided to warn. 如果應用程式需要舊版 支援,請在 中使用下列任何方法停用 : If the application needs old version support, please use any of the following methods to disable it: 健康情況檢查可作為具有端點路由的路由器軟體。 A health check can be used as a router software with a peer router . 新增 以搭配端點路由使用健康情況檢查。 方法接受類似 的引數。 使用 優於 的優點是能夠套用授權,並更精細地控制比對原則。 New to match the end-point path by using a health check. Method accepts an argument like this. Use the advantage of being able to apply the authorization and control the principle more precisely. 在下列範例中, 會在 呼叫健康情況檢查端點: Call health check peer in the following examples: ASP.NET Core 3.0 範本會使用一般主機。 舊版使用 Web 主機。 下列程式碼顯示 ASP.NET Core 3.0 範本產生的 類別: ASP.NET Core 3.0 Template will use . The old version will use IWebHostBuilder 會保留在 3.0 中,而且是上述程式碼範例中所見的 類型。 WebHostBuilder 將在未來的版本中淘汰,並由 取代。
從 到 的最重大變更是相依性插入 (DI)。 使用 時,您只能將下列項目插入 的建構函式中: The most significant change from . When used, you can only insert the following items into the construction function: DI 限制式: DI Restricted: 如需詳細資訊,請參閱避免在 ASP.NET Core 3 中的啟動服務插入。 For more detailed information, please refer to in ASP.NET Core 3. Microsoft.AspNetCore.Authorization.dll 中的 ASP.NET Core 2.2 和較低 方法: ASP.NET Core 2.2 from Microsoft.AspNetCore.Authorization.dll and lower method: 使用 Microsoft.AspNetCore.Authorization.dll 和 Microsoft.AspNetCore.Authorization.Policy.dll 的應用程式不會受到影響。 Applications using Microsoft.AspNetCore.Authoralation.dll and Microsoft.AspNetCore.Authorization.Policy.dll will not be affected. 未使用 Microsoft.AspNetCore.Authorization.Policy.dll 的應用程式應該執行下列其中一項作業: Applications that do not use Microsoft. AspNetCore. Association. Policy.dll should perform one of the following: 如需詳細資訊,請參閱 ) 多載中的中斷性變更位於不同組件 #386。 For more detailed information, please refer to . ASP.NET Core 3.0 的 Identity UI 更新: ASP.NET Core 3.0 Identity UI Update: SignalR JavaScript 用戶端已從 變更為 。 若要回應這項變更,請變更 檔案、 陳述式和 ECMAScript 陳述式中的參考。 The SignalR JavaScript client has been changed from one to another. To respond to this change, change references in files, narratives and ECMAScript statements. 現在是用戶端和伺服器所使用的預設中樞通訊協定。 This is the default communication protocol used by users and servers. 在 中,呼叫 以設定序列化程式選項。 In, the call to configure the sequenced program selection. 伺服器: server: 用戶端: client: 如果您使用在 System.Text.Json 中不支援的 Newtonsoft.Json 功能,您可以切換回 。 請參閱本文中稍早的在 ASP.NET Core 3.0 SignalR 專案中使用 Newtonsoft.Json。 If you use
Microsoft.Extensions.Caching.Redis 套件不適用於 ASP.NET Core 3.0 或更新版本應用程式。 將套件參考取代為 Microsoft.Extensions.Caching.StackExchangeRedis。 如需詳細資訊,請參閱 ASP.NET Core 中的分散式快取。 Microsoft.Extension.Caching. Redis is not suitable for ASP.NET Core 3.0 or for an updated version of the application. For more detailed information, refer to . For more detailed information, refer to . 在 ASP.NET Core 3.0 以前,檢視的執行階段編譯是架構的隱含功能。 執行階段編譯補充檢視的建置時間編譯。 可讓架構在修改檔案時編譯 Razor 檢視和頁面 ( 檔案),而不需要重建整個應用程式。 此功能支援在 IDE 中快速編輯和重新整理瀏覽器以檢視變更的案例。 Prior to ASP.NET Core 3.0, the viewing of the executive segment was an implicit function of the architecture. The running segment compiles the construction time compilation of the add-on view. It allows the structure to compile the Razor view and page (files) without rebuilding the whole application when changing the file. This function supports quick editing and reorganizing the browser in IDE to view the change cases. 在 ASP.NET Core 3.0 中,執行階段編譯是加入案例。 建置時間編譯是預設啟用之檢視編譯的唯一機制。 執行階段依賴 Visual Studio 或 Visual Studio Code 中的 dotnet-watch,在偵測到對 檔案的變更時重建專案。 在 Visual Studio 中,對專案中 、 或 檔案的變更會執行 (Ctrl+F5),但是未偵錯 (F5),觸發專案的重新編譯。 In ASP.NET Core 3.0, an executive session is added to the case. Building time is the only mechanism for pre-enacting a pre-enacted view compilation. The implementation phase relies on , re-establishing the project in the context of the detection of file changes. In Visual Studio, re-editing of the project or file ( 若要在 ASP.NET Core 3.0 專案中啟用執行階段編譯: To enable an executive session compilation in the ASP.NET Core 3.0 project: 安裝 Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation NuGet 套件。 Installed Microsoft. AspNetCore. Mvc. Razor. Runtimecompilation NuGet package. 更新 以呼叫 : Update to call: 針對 ASP.NET Core MVC,請使用下列程式碼: For ASP.NET Core MVC, use the following code: 針對 ASP.NET Core Razor Pages,請使用下列程式碼: For ASP.NET Core Razor Pages, use the following code: https://github.com/aspnet/samples/tree/main/samples/aspnetcore/mvc/runtimecompilation 的範例會顯示在開發環境中有條件地啟用執行階段編譯的範例。 https://gethub.com/aspnet/samples/tree/main/samples/aspnetcore/mvc/runtimecompilation shows examples of the limited introduction of executive paragraph compilation in the development environment. 如需 Razor 檔案編譯的詳細資訊,請參閱 ASP.NET Core 中的 Razor 檔案編譯。 For details of Razor file compilation, please refer to
程式庫通常需要支援多個版本的 ASP.NET Core。 針對舊版 ASP.NET Core 編譯的大多數程式庫應該會繼續運作,不會發生問題。 下列條件需要應用程式交叉編譯: The library usually needs to support multiple versions of ASP.NET Core. Most of the databases compiled in the old ASP.NET Core should continue to operate without problems. The following conditions require applications to be cross-compiled: 例如: For example: 使用 來啟用 ASP.NET Core 3.0 特定 API: ASP.NET Core 3.0 Specific API: 如需在類別庫中使用 ASP.NET Core API 的詳細資訊,請參閱在類別庫中使用 ASP.NET Core API。 For more detailed information about ASP.NET Core API, refer to ASP.NET Core API at . .NET Core 3.0 和更新版本中的驗證系統會將不可為 Null 的參數或繫結屬性視為具有 屬性。 如需詳細資訊,請參閱 [必要] 屬性。 The verification system in.NET Core 3.0 and the updated version will consider non-Null parameters or binding properties as properties. . 刪除專案目錄中的 bin 和 obj 資料夾。 Delete the folders bin and obj in the project directory. 針對直接搭配一般主機使用 TestServer 的應用程式,請在 ConfigureWebHost 中的 IWebHostBuilder 上建立 : The general host of 檢閱中斷性變更: Could not close temporary folder: %s 警告 This function is EXPERIMENTAL. 由於路由中的錯誤 (bug),catch-all 參數可能會錯誤比對路由。 受到此錯誤 (bug) 影響的應用程式具有下列特性: 如需發生此錯誤 (bug) 的範例案例,請參閱 GitHub 錯誤 (bug) 18677 和 16579。 For examples of this error (bug) see GitHub error (bug) 18677 and 16579. 這個錯誤 (bug) 的加入修正包含在 .NET Core 3.1.301 SDK 和更新版本。 下列程式碼會設定修正此錯誤 (bug) 的內部參數: The addition correction for the error (bug) is contained in . NET Core 3.1.301 SDK update. The following code sets the internal parameters for correcting the error (bug): .NET Core 推出到 Azure App Service 已完成。 所有 Azure App Service 資料中心都可使用 .NET Core 3.0。 The.NET Core launch to Azure App Service has been completed. All Azure App Service Data Centers are available.NET Core 3.0. 如果在安裝 Visual Studio 時,ASP.NET Core 模組 (ANCM) 不是選取的元件,或者如果系統上已安裝舊版的 ANCM,請下載最新的 .NET Core 裝載套件組合安裝程式 (直接下載),並執行安裝程式。 如需詳細資訊,請參閱裝載組合套件。 If is not an selected component, or if old versions of ANCM are installed on the system, please download ("directive")
注册有任何问题请添加
微信:MVIP619
拉你进入群
打开微信扫一扫 添加客服 进入交流群
使用 Docker 的架構相依組建
.
CORS
授權
自訂授權處理常式
共用架構中的 SignalR 組件
從控制器動作名稱移除非同步尾碼
連結產生的變更
1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。