拙网论坛

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 202|回复: 0

Introduction to ASP.NET Core

[复制链接]

949

主题

1001

帖子

3736

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
3736
发表于 2019-8-30 10:47:38 | 显示全部楼层 |阅读模式


[size=2.5]Introduction to ASP.NET Core
  • 04/07/2019
  • 5 minutes to read

By [color=var(--primary-base)]Daniel Roth, [color=var(--primary-base)]Rick Anderson, and [color=var(--primary-base)]Shaun Luttin
ASP.NET Core is a cross-platform, high-performance, [color=var(--primary-base)]open-source framework for building modern, cloud-based, Internet-connected applications. With ASP.NET Core, you can:
  • Build web apps and services, [color=var(--primary-base)]IoT apps, and mobile backends.
  • Use your favorite development tools on Windows, macOS, and Linux.
  • Deploy to the cloud or on-premises.
  • Run on [color=var(--primary-base)].NET Core or .NET Framework.
Why choose ASP.NET Core?
Millions of developers have used (and continue to use) [color=var(--primary-base)]ASP.NET 4.x to create web apps. 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 provides the following benefits:
  • A unified story for building web UI and web APIs.
  • Architected for testability.
  • [color=var(--primary-base)]Razor Pages makes coding page-focused scenarios easier and more productive.
  • [color=var(--primary-base)]Blazor lets you use C# in the browser alongside JavaScript. Share server-side and client-side app logic all written with .NET.
  • Ability to develop and run on Windows, macOS, and Linux.
  • Open-source and [color=var(--primary-base)]community-focused.
  • Integration of [color=var(--primary-base)]modern, client-side frameworks and development workflows.
  • A cloud-ready, environment-based [color=var(--primary-base)]configuration system.
  • Built-in [color=var(--primary-base)]dependency injection.
  • A lightweight, [color=var(--primary-base)]high-performance, and modular HTTP request pipeline.
  • Ability to host on [color=var(--primary-base)]IIS, [color=var(--primary-base)]Nginx, [color=var(--primary-base)]Apache, [color=var(--primary-base)]Docker, or self-host in your own process.
  • Side-by-side app versioning when targeting [color=var(--primary-base)].NET Core.
  • Tooling that simplifies modern web development.
Build web APIs and web UI using ASP.NET Core MVC
ASP.NET Core MVC provides features to build [color=var(--primary-base)]web APIs and [color=var(--primary-base)]web apps:
  • The [color=var(--primary-base)]Model-View-Controller (MVC) pattern helps make your web APIs and web apps testable.
  • [color=var(--primary-base)]Razor Pages is a page-based programming model that makes building web UI easier and more productive.
  • [color=var(--primary-base)]Razor markup provides a productive syntax for [color=var(--primary-base)]Razor Pages and [color=var(--primary-base)]MVC views.
  • [color=var(--primary-base)]Tag Helpers enable server-side code to participate in creating and rendering HTML elements in Razor files.
  • Built-in support for [color=var(--primary-base)]multiple data formats and content negotiation lets your web APIs reach a broad range of clients, including browsers and mobile devices.
  • [color=var(--primary-base)]Model binding automatically maps data from HTTP requests to action method parameters.
  • [color=var(--primary-base)]Model validation automatically performs client-side and server-side validation.
Client-side development
ASP.NET Core integrates seamlessly with popular client-side frameworks and libraries, including [color=var(--primary-base)]Blazor, [color=var(--primary-base)]Angular, [color=var(--primary-base)]React, and [color=var(--primary-base)]Bootstrap. For more information, see [color=var(--primary-base)]Introduction to Blazor in ASP.NET Core and related topics under Client-side development.

ASP.NET Core targeting .NET Framework
ASP.NET Core 2.x can target .NET Core or .NET Framework. ASP.NET Core apps targeting .NET Framework aren't cross-platform—they run on Windows only. Generally, ASP.NET Core 2.x is made up of [color=var(--primary-base)].NET Standard libraries. Libraries written with .NET Standard 2.0 run on any [color=var(--primary-base)].NET platform that implements .NET Standard 2.0.
ASP.NET Core 2.x is supported on .NET Framework versions that implement .NET Standard 2.0:
  • .NET Framework latest version is strongly recommended.
  • .NET Framework 4.6.1 and later.
ASP.NET Core 3.0 and later will only run on .NET Core. For more details regarding this change, see [color=var(--primary-base)]A first look at changes coming in ASP.NET Core 3.0.
There are several advantages to targeting .NET Core, and these advantages increase with each release. Some advantages of .NET Core over .NET Framework include:
  • Cross-platform. Runs on macOS, Linux, and Windows.
  • Improved performance
  • Side-by-side versioning
  • New APIs
  • Open source
We're working hard to close the API gap from .NET Framework to .NET Core. The [color=var(--primary-base)]Windows Compatibility Pack made thousands of Windows-only APIs available in .NET Core. These APIs weren't available in .NET Core 1.x.
Recommended learning path
We recommend the following sequence of tutorials and articles for an introduction to developing ASP.NET Core apps:
* There is a new [color=var(--primary-base)]web API tutorial that you follow entirely in the browser, no local IDE installation required. The code runs in an [color=var(--primary-base)]Azure Cloud Shell, and [color=var(--primary-base)]curl is used for testing.
How to download a sample
Many of the articles and tutorials include links to sample code.
Preprocessor directives in sample code
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. 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.
For example, the following #define symbol list indicates that four scenarios are available (one scenario per symbol). The current sample configuration runs the TemplateCode scenario:
[color=var(--text)][backcolor=var(--body-background-dark)][size=0.8]C#Copy
#define TemplateCode // or LogFromMain or ExpandDefault or FilterInCode
To change the sample to run the ExpandDefault scenario, define the ExpandDefault symbol and leave the remaining symbols commented-out:
[color=var(--text)][backcolor=var(--body-background-dark)][size=0.8]C#Copy
#define ExpandDefault // TemplateCode or LogFromMain or FilterInCode
For more information on using [color=var(--primary-base)]C# preprocessor directives to selectively compile sections of code, see [color=var(--primary-base)]#define (C# Reference) and [color=var(--primary-base)]#if (C# Reference).
Regions in sample code
Some sample apps contain sections of code surrounded by [color=var(--primary-base)]#region and [color=var(--primary-base)]#endregion C# statements. The documentation build system injects these regions into the rendered documentation topics.
Region names usually contain the word "snippet." The following example shows a region named snippet_FilterInCode:
[color=var(--text)][backcolor=var(--body-background-dark)][size=0.8]C#Copy
<code class="lang-csharp" data-author-content="#region snippet_FilterInCodeWebHost.CreateDefaultBuilder(args)    .UseStartup()    .ConfigureLogging(logging =>        logging.AddFilter(&quot;System&quot;, LogLevel.Debug)            .AddFilter(&quot;Microsoft&quot;, LogLevel.Trace))            .Build();#endregion" style="box-sizing: inherit; font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; font-size: 1em; direction: ltr; position: relative; border: 0px; display: block; line-height: 19px;">#region snippet_FilterInCodeWebHost.CreateDefaultBuilder(args)    .UseStartup<Startup>()    .ConfigureLogging(logging =>        logging.AddFilter("System", LogLevel.Debug)            .AddFilter<DebugLoggerProvider>("Microsoft", LogLevel.Trace))            .Build();#endregion
The preceding C# code snippet is referenced in the topic's markdown file with the following line:
[color=var(--text)][backcolor=var(--body-background-dark)][size=0.8]MarkdownCopy
[!code-csharp[](sample/SampleApp/Program.cs?name=snippet_FilterInCode)]
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.
For more information, see [color=var(--primary-base)]Contribute to the ASP.NET documentation: Code snippets.
Next steps
For more information, see the following resources:
Feedback
https://docs.microsoft.com/en-us/aspnet/core/index?view=aspnetcore-2.2

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|抱朴守拙BBS

GMT+8, 2025-5-25 21:30 , Processed in 0.189839 second(s), 18 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表