ASP.NET Core の概要Introduction to ASP.NET Core
著者: Daniel Roth、Rick Anderson、Shaun LuttinBy Daniel Roth, Rick Anderson, and Shaun Luttin
ASP.NET Core は、インターネットに接続された最新のクラウド ベース アプリケーションを構築するための、クロス プラットフォームで高パフォーマンスのオープン ソース フレームワークです。ASP.NET Core is a cross-platform, high-performance, open-source framework for building modern, cloud-based, Internet-connected applications. ASP.NET Core では次のことができます。With ASP.NET Core, you can:
- Web アプリ、Web サービス、IoT アプリ、モバイル バックエンドを構築する。Build web apps and services, IoT apps, and mobile backends.
- Windows、macOS、Linux で好みの開発ツールを使う。Use your favorite development tools on Windows, macOS, and Linux.
- クラウドまたはオンプレミスに展開する。Deploy to the cloud or on-premises.
- .NET Core または .NET Framework 上で実行する。Run on .NET Core or .NET Framework.
ASP.NET Core を使う理由Why use ASP.NET Core?
何百万人もの開発者が、これまで、そして現在も、Web アプリの作成に ASP.NET 4.x を使っています。Millions of developers have used (and continue to use) ASP.NET 4.x to create web apps. ASP.NET Core は ASP.NET 4.x を設計し直したものであり、無駄のないモジュール形式のフレームワークになるようにアーキテクチャが変更されています。ASP.NET Core is a redesign of ASP.NET 4.x, with architectural changes that result in a leaner, more modular framework.
ASP.NET Core の利点は次のとおりです。ASP.NET Core provides the following benefits:
- Web UI と Web API を構築するプロセスの統一。A unified story for building web UI and web APIs.
- テストの容易性を考慮したアーキテクチャ。Architected for testability.
- Razor Pagesにより、ページ コーディングに重点を置いたシナリオがより簡略化され、その生産性が高められます。Razor Pages makes coding page-focused scenarios easier and more productive.
- Windows、macOS、Linux 上で開発および実行できること。Ability to develop and run on Windows, macOS, and Linux.
- オープン ソースでコミュニティ重視。Open-source and community-focused.
- 最新のクライアント側フレームワークと開発ワークフローの統合。Integration of modern, client-side frameworks and development workflows.
- クラウド対応で環境ベースの構成システム。A cloud-ready, environment-based configuration system.
- 組み込まれている依存性の注入。Built-in dependency injection.
- 軽量で高パフォーマンスのモジュール化された HTTP 要求パイプライン。A lightweight, high-performance, and modular HTTP request pipeline.
- IIS、Nginx、Apache、Docker でホストする、または独自のプロセスで自己ホストする機能。Ability to host on IIS, Nginx, Apache, Docker, or self-host in your own process.
- .NET Core に対応する場合は、アプリのサイド バイ サイド バージョン管理をサポート。Side-by-side app versioning when targeting .NET Core.
- 最新の Web 開発を簡単にするツール。Tooling that simplifies modern web development.
ASP.NET Core MVC を使って Web API と Web UI を構築するBuild web APIs and web UI using ASP.NET Core MVC
ASP.NET Core MVC は、Web API と Web アプリを構築する機能を備えています。ASP.NET Core MVC provides features to build web APIs and web apps:
- モデル ビュー コントローラー (MVC) パターンは、Web API と Web アプリをテスト可能にするのに役立ちます。The Model-View-Controller (MVC) pattern helps make your web APIs and web apps testable.
- Razor ページはページ ベースのプログラミング モデルであり、Web UI の開発を容易にし、生産性を高めます。Razor Pages is a page-based programming model that makes building web UI easier and more productive.
- Razor マークアップでは、Razor ページおよび MVC ビュー用に生産性の高い構文が提供されます。Razor markup provides a productive syntax for Razor Pages and MVC views.
- タグ ヘルパーを使うと、Razor ファイルでの HTML 要素の作成とレンダリングに、サーバー側コードを組み込むことができます。Tag Helpers enable server-side code to participate in creating and rendering HTML elements in Razor files.
- 複数のデータ形式とコンテンツ ネゴシエーションの組み込みサポートにより、Web API はブラウザーやモバイル デバイスなどのさまざまなクライアントと接続できます。Built-in support for multiple data formats and content negotiation lets your web APIs reach a broad range of clients, including browsers and mobile devices.
- モデル バインドは、HTTP 要求からアクション メソッドのパラメーターにデータを自動的にマップします。Model binding automatically maps data from HTTP requests to action method parameters.
- モデル検証では、クライアント側とサーバー側の検証が自動的に実行されます。Model validation automatically performs client-side and server-side validation.
クライアント側の開発Client-side development
ASP.NET Core は、人気のあるクライアント側のフレームワークとライブラリ (Razor Components、Angular、React、Bootstrap など) をシームレスに統合します。ASP.NET Core integrates seamlessly with popular client-side frameworks and libraries, including Razor Components, Angular, React, and Bootstrap. 詳細については、Razor Components に関する記事とクライアント側の開発の関連トピックを参照してください。For more information, see Razor Components and related topics under Client-side development.
.NET Framework を対象とする ASP.NET CoreASP.NET Core targeting .NET Framework
ASP.NET Core 2.x は、.NET Core または .NET Framework を対象にすることができます。ASP.NET Core 2.x can target .NET Core or .NET Framework. .NET Framework を対象とする ASP.NET Core アプリはクロスプラットフォームではありません—Windows でのみ実行されます。ASP.NET Core apps targeting .NET Framework aren't cross-platform—they run on Windows only. 一般に、ASP.NET Core 2.x は .NET Standard ライブラリで構成されています。Generally, ASP.NET Core 2.x is made up of .NET Standard libraries. .NET Standard 2.0 で記述されたアプリは、.NET Standard 2.0 がサポートされていればどこでも実行できます。Apps written with .NET Standard 2.0 run anywhere that .NET Standard 2.0 is supported.
ASP.NET Core 2.x は、.NET Standard 2.0 との互換性を持つ .NET Framework バージョンにおいてサポートされています。ASP.NET Core 2.x is supported on .NET Framework versions compatible with .NET Standard 2.0:
- .NET framework 4.7.1 以降を強くお勧めします。.NET Framework 4.7.1 and later is strongly recommended.
- .NET Framework 4.6.1 以降。.NET Framework 4.6.1 and later.
ASP.NET Core 3.0 以降は、.NET Core でのみ実行されます。ASP.NET Core 3.0 and later will only run on .NET Core. この変更に関する詳細については、「ASP.NET Core 3.0 で導入される変更について」を参照してください。For more details regarding this change, see A first look at changes coming in ASP.NET Core 3.0.
.NET Core を対象とする利点はいくつかあり、リリースのたびにその利点が増えています。There are several advantages to targeting .NET Core, and these advantages increase with each release. .NET Framework 経由による .NET Core には次のような利点があります。Some advantages of .NET Core over .NET Framework include:
- クロスプラットフォームである。Cross-platform. macOS、Linux、Windows で実行できる。Runs on macOS, Linux, and Windows.
- パフォーマンスの向上Improved performance
- side-by-side でのバージョン管理Side-by-side versioning
- 新しい APINew APIs
- ソースを開くOpen source
.NET Framework と .NET Core の間にある API のギャップを埋めるため、鋭意作業中です。We're working hard to close the API gap from .NET Framework to .NET Core. Windows 互換機能パックにより、多くの Windows 限定の API が .NET Core で利用できるようになりました。The Windows Compatibility Pack made thousands of Windows-only APIs available in .NET Core. このような API は .NET Core 1.x で利用できませんでした。These APIs weren't available in .NET Core 1.x.
サンプルをダウンロードする方法How to download a sample
多くの記事やチュートリアルにサンプル コードへのリンクが含まれています。Many of the articles and tutorials include links to sample code.
- ASP.NET リポジトリの zip ファイルをダウンロードします。Download the ASP.NET repository zip file.
- Docs-master.zip ファイルを解凍します。Unzip the Docs-master.zip file.
- サンプル リンクの URL を使って、サンプル ディレクトリに移動します。Use the URL in the sample link to help you navigate to the sample directory.
サンプル コードのプリプロセッサ ディレクティブPreprocessor directives in sample code
複数のシナリオを示すため、サンプル アプリでは #define
と #if-#else/#elif-#endif
の C# ステートメントを使用してさまざまなサンプル コードのセクションを選択してコンパイルし、実行します。To demonstrate multiple scenarios, sample apps use the #define
and #if-#else/#elif-#endif
C# statements to selectively compile and run different sections of sample code. このアプローチを活用するサンプルでは、C# ファイルの上部にある #define
ステートメントを、実行するシナリオに関連付けられたシンボルに設定します。For those samples that make use of this approach, set the #define
statement at the top of the C# files to the symbol associated with the scenario that you want to run. 一部のサンプルでは、シナリオを実行するために複数のファイルの上部でシンボルを設定する必要があります。Some samples require setting the symbol at the top of multiple files in order to run a scenario.
たとえば、次の #define
のシンボル一覧は、4 つのシナリオが使用可能である (シンボルごとに 1 つのシナリオ) ことを示しています。For example, the following #define
symbol list indicates that four scenarios are available (one scenario per symbol). 現在のサンプル構成では TemplateCode
のシナリオが実行されます。The current sample configuration runs the TemplateCode
scenario:
#define TemplateCode // or LogFromMain or ExpandDefault or FilterInCode
ExpandDefault
のシナリオを実行するサンプルを変更するには、ExpandDefault
のシンボルを定義し、残りのシンボルをコメント アウトしたままにします。To change the sample to run the ExpandDefault
scenario, define the ExpandDefault
symbol and leave the remaining symbols commented-out:
#define ExpandDefault // TemplateCode or LogFromMain or FilterInCode
C# プリプロセッサ ディレクティブを使用してコードのセクションを選択的にコンパイルする方法の詳細については、「#define (C# リファレンス)」および「#if (C# リファレンス)」を参照してください。For more information on using C# preprocessor directives to selectively compile sections of code, see #define (C# Reference) and #if (C# Reference).
サンプル コードのリージョンRegions in sample code
一部のサンプル アプリには、#region と #end-region の C# ステートメントに囲まれたコードのセクションが含まれています。Some sample apps contain sections of code surrounded by #region and #endregion C# statements. ドキュメントのビルド システムによって、レンダリングされたドキュメントのトピックにこのリージョンが挿入されます。The documentation build system injects these regions into the rendered documentation topics.
リージョン名には通常、"snippet" という単語が含まれています。Region names usually contain the word "snippet." 次の例は snippet_FilterInCode
という名前のリージョンを示しています。The following example shows a region named snippet_FilterInCode
:
#region snippet_FilterInCode
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.ConfigureLogging(logging =>
logging.AddFilter("System", LogLevel.Debug)
.AddFilter<DebugLoggerProvider>("Microsoft", LogLevel.Trace))
.Build();
#endregion
先述の C# コード スニペットは、トピックのマークダウン ファイルの次の行で示されています。The preceding C# code snippet is referenced in the topic's markdown file with the following line:
[!code-csharp[](sample/SampleApp/Program.cs?name=snippet_FilterInCode)]
コードを囲む #region
と #endregion
のステートメントは安全に無視 (または削除) することができます。You may safely ignore (or remove) the #region
and #endregion
statements that surround the code. トピックで説明されているサンプル シナリオを実行する予定がある場合は、これらのステートメント内のコードを変更しないでください。Don't alter the code within these statements if you plan to run the sample scenarios described in the topic. 他のシナリオを試す場合は、自由にコードを変更できます。Feel free to alter the code when experimenting with other scenarios.
詳細については、「Contribute to the ASP.NET documentation: Code snippets (ASP.NET に貢献する: コード スニペット)」を参照してください。For more information, see Contribute to the ASP.NET documentation: Code snippets.
次の手順Next steps
詳細については、次のリソースを参照してください。For more information, see the following resources:
- Razor ページの概要Get started with Razor Pages
- Visual Studio を使用して Azure に ASP.NET Core アプリを発行する
- ASP.NET Core の基礎ASP.NET Core fundamentals
- 週 1 回の ASP.NET Community Standup では、チームの進行状況とプランが報告され、The weekly ASP.NET community standup covers the team's progress and plans. 新しいブログやサード パーティ製ソフトウェアが取り上げられています。It features new blogs and third-party software.
フィードバック
お客様のご意見をお寄せください。 お寄せいただく内容の種類を選択:
このフィードバック システムは、GitHub Issues を利用して構築されています。 詳しくは、ブログをご覧ください。
フィードバックを読み込んでいます...