索引:

目录索引

Introduction to ASP.NET Core

Asp.net core 介绍

By Daniel Roth, Rick Anderson and Shaun Luttin

Meng.Net 自译

ASP.NET Core is a significant redesign of ASP.NET. This topic introduces the new concepts in ASP.NET Core and explains how they help you

Asp.net core 是 asp.net 的重大重构版本 , 本文介绍asp.net core新的概念,并且解释你怎样

develop modern web apps.

开发现代web 应用.

Sections:

What is ASP.NET Core

ASP.NET Core is a new open-source and cross-platform framework for building modern cloud based internet connected applications, such as

Asp.net core 是一个新的 ,开源的,跨平台的框架, 可用来构建现代的,基于云连接的应用程序,例如:

web apps, IoT apps and mobile backends. ASP.NET Core apps can run on .NET Core or on the full .NET Framework. It was architected to

web应用,物联网应用,移动后台. Asp.net core 程序 可以运行在.net core 或者 .net framework 上. 它被构建

provide an optimized development framework for apps that are deployed to the cloud or run on-premises. It consists of modular components

提供一个最优化的应用开发框架,可以部署在云或运行在本地. 它由最小限度模块化组件

with minimal overhead, so you retain flexibility while constructing your solutions. You can develop and run your ASP.NET Core apps cross-

构成. 因此构建程序时你可以保持灵活性. 你可以 跨平台 开发/运行你的asp.net core 应用 在

platform on Windows, Mac and Linux. ASP.NET Core is open source at GitHub.

Windows /mac /linux 系统, asp.net core 在github 上是开源的 .

Why build ASP.NET Core

The first preview release of ASP.NET came out almost 15 years ago as part of the .NET Framework. Since then millions of developers have

作为.net framework 的一部分, 第一个asp.net 预览 已放发布超过15年了 . 从此,数百万的开发者

used it to build and run great web apps, and over the years we have added and evolved many capabilities to it.

用它 构建/运行 伟大的web应用, 并且在这些年中我们给他新增并扩展了很多功能.

ASP.NET Core has a number of architectural changes that result in a much leaner and modular framework. ASP.NET Core is no longer based on

Asp.net core 有一些结构设计上的改变,使得其高度简洁,模块化. Asp.net core 不在基于 system.web.dll .

System.Web.dll. It is based on a set of granular and well factored NuGet packages. This allows you to optimize your app to include just the

它基于 一个细粒度的 / 因素分解的 nuget 包集合 . 这样 你就可以优化你的应用,使其仅包含

NuGet packages you need. The benefits of a smaller app surface area include tighter security, reduced servicing, improved performance, and

你需要的 nuget 文件.  好处是 一个小的 引用 但是包含了安全/低耗/演进/

decreased costs in a pay-for-what-you-use model.

降低你的花费开销.

With ASP.NET Core you gain the following foundational improvements:

使用 asp.net core 你获得了 以下基本的改进:

  • A unified story for building web UI and web APIs

一个 构建 web UI / web api 的统一模式

集成 现代的客户端框架 及 开发流程

一个 基于云的 环境配置系统

内嵌 依赖注入 DI

  • New light-weight and modular HTTP request pipeline

新的 轻量级的 / 模块化 的 http 请求管道

  • Ability to host on IIS or self-host in your own process

可以 宿主与iis 或者 自宿主

  • Built on .NET Core, which supports true side-by-side app versioning

以 .net core 作为基础, 支持 并行 版本 控制

  • Ships entirely as NuGet packages

完全以 nuget 包作为承载

  • New tooling that simplifies modern web development

新的工具简化现代web开发

  • Build and run cross-platform ASP.NET apps on Windows, Mac and Linux

编译并跨平台运行,在 windows/mac/linux 系统上

  • Open source and community focused

开源/开源社区,支持的

Application anatomy   

应用程序解析

An ASP.NET Core app is simply a console app that creates a web server in its Main method:

一个asp.net core 应用,是一个简单的控制台应用在它的main方法中创建的web服务.

 using System;
using Microsoft.AspNetCore.Hosting; namespace aspnetcoreapp
{
public class Program
{
public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseKestrel()
.UseStartup<Startup>()
.Build(); host.Run();
}
}
}

Program.cs

Main uses WebHostBuilder, which follows the builder pattern, to create a web application host. The builder has methods that define the web server

Main 方法使用 WebHostBuilder 创建了一个 Host 。 WebHostBuilder 中 定义了 创建web服务器(Kestrel)的方法。

(for example UseKestrel) and the startup class (UseStartup). In the example above, the Kestrel web server is used, but other web servers can be

在上面的例子中,指定使用了 Kestrel 服务器,同时也可以指定使用其它的服务器(如IIS)。

specified. We’ll show more about UseStartup in the next section. WebHostBuilder provides many optional methods including UseIISIntegration for

关于 Startup 我们在下面的章节中将会讲解更多。WebHostBuilder 类提供了很多可选方法,如 UseIISIntegration() 可以使用IIS宿主

hosting in IIS and IIS Express and UseContentRoot for specifying the root content directory. The Build and Run methods build the IWebHost that

程序,UseContentRoot()  提供根目录。Build()  创建 热点

will host the app and start it listening for incoming HTTP requests.

Run()  将开始监听程序的 HTTP 请求。

Startup

The UseStartup method on WebHostBuilder specifies the Startup class for your app.

WebHostBuilder 类 UseStartup() 方法使用你在程序中指定的 Startup 类。

 public class Program
{
public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseKestrel()
.UseStartup<Startup>()
.Build(); host.Run();
}
}

Program.cs

The Startup class is where you define the request handling pipeline and where any services needed by the app are configured. The Startup class

在 Startup 类中你将定义 请求处理管道 和 注册配置应用所需的 服务。

must be public and contain the following methods:

Startup 类必须是 public 的 ,并且包含下面两个方法:

 public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
} public void Configure(IApplicationBuilder app)
{
}
}

Startup.cs

  • ConfigureServices defines the services (see Services below) used by your app (such as the ASP.NET MVC Core framework, Entity Framework

  ConfigureServices() 定义了应用中需要的服务,如:ASP.NET MVC Core、Entity Framework Core、Identity 等等。

Core, Identity, etc.)

  • Configure defines the middleware in the request pipeline

  Configure() 定义了请求管道中的中间件。

Services

A service is a component that is intended for common consumption in an application. Services are made available through dependency injection.

service 是一种在 应用 中被用来公共使用的 组件。服务(Services)通过依赖注入(DI)的方式使用。

ASP.NET Core includes a simple built-in inversion of control (IoC) container that supports constructor injection by default, but can be easily

Asp.net core 内置了IOC 容器,这个容器默认使用构造函数注入的方式,他可以简易的替换掉你自己选择的第三方IOC容器。

replaced with your IoC container of choice. In addition to its loose coupling benefit, DI makes services available throughout your app. For

除了松耦合的好处外,DI 让 services 在你的整个应用程序过程中都有效,

example, Logging is available throughout your app. See Dependency Injection for more details.

如:Logging

Middleware

In ASP.NET Core you compose your request pipeline using Middleware. ASP.NET Core middleware performs asynchronous logic on an

在 asp.net core 中,你将用中间件组成你的请求管道。中间件在 HttpContext 中将异步调用执行,一个执行完后会按顺序执行下一个

HttpContext and then either invokes the next middleware in the sequence or terminates the request directly. You generally “Use” middleware by

或者直接终止退出请求。你通常会这样使用中间件:

taking a dependency on a NuGet package and invoking a corresponding UseXYZ extension method on the IApplicationBuilder in the Configure

在Configure() 中 IApplicationBuilder 实例上 使用形如 UseXYZ 的扩展方法。

method.

ASP.NET Core comes with a rich set of prebuilt middleware:

Asp.net core 官方 提供了一组可用的中间件:

You can also author your own custom middleware.

同样,你也可以自定义你自己的中间件。

You can use any OWIN-based middleware with ASP.NET Core. See Open Web Interface for .NET (OWIN) for details.

Servers

The ASP.NET Core hosting model does not directly listen for requests; rather it relies on an HTTP server implementation to forward the request

Asp.net core 的host 模块不会直接监听请求;当然了,它依赖于一个 HTTP server 的实现。

to the application. The forwarded request is wrapped as a set of feature interfaces that the application then composes into an HttpContext.

实现类转递过来的请求按照借口约定组装进 HttpContext 中。

ASP.NET Core includes a managed cross-platform web server, called Kestrel, that you would typically run behind a production web server like

Asp.net core 包含一个被托管的、跨平台的web服务器(Kestrel),就像iis 或 nginx 一样。

IIS or nginx.

Content root

The content root is the base path to any content used by the app, such as its views and web content. By default the content root is the same as

根目录(The content root)是应用中所有内容的根目录,如 views 。默认情况下,

application base path for the executable hosting the app; an alternative location can be specified with WebHostBuilder.

它与宿主app执行的应用根目录相同;也可用 WebHostBuilder 指定。

Web root

The web root of your app is the directory in your project for public, static resources like css, js, and image files. The static files middleware will

The web root 目录是你应用中 静态资源文件(css、js)等的根目录。

only serve files from the web root directory (and sub-directories) by default. The web root path defaults to <content root>/wwwroot, but you can

默认情况下,静态资源中间件只有在文件从web root 目中请求时才服务。默认情况下 The web root 的路径是

specify a different location using the WebHostBuilder.

<content root>/wwwroot ,同时此路径你也可以在WebHostBuilder 中另外指定不同的路径。

Configuration

ASP.NET Core uses a new configuration model for handling simple name-value pairs. The new configuration model is not based on

Asp.ent core 用了一个新的 配置处理模块 来处理简单的 键-值 对。 新的配置处理模块不再基于 System.Configuration

System.Configuration or web.config; rather, it pulls from an ordered set of configuration providers. The built-in configuration providers support a

web.config ; 当然,它从配置提供程序中拉去。 内置的配置提供程序支持

variety of file formats (XML, JSON, INI) and environment variables to enable environment-based configuration. You can also write your own

多种类型的文件(xml、json、ini)并且 环境变量可以基于环境配置。同样,你也可以自己写

custom configuration providers.

自定义的配置提供程序。

See Configuration for more information.

Environments

Environments, like “Development” and “Production”, are a first-class notion in ASP.NET Core and can be set using environment variables. See

像 Development 、 Production 环境,在 asp.net core 中是一种优秀的概念 , 并且是可配置使用的环境变量。

Working with Multiple Environments for more information.

Build web UI and web APIs using ASP.NET Core MVC

  • You can create well-factored and testable web apps that follow the Model-View-Controller (MVC) pattern. See MVC and Testing.
  • You can build HTTP services that support multiple formats and have full support for content negotiation. See Formatting Response Data
  • Razor provides a productive language to create Views
  • Tag Helpers enable server-side code to participate in creating and rendering HTML elements in Razor files
  • You can create HTTP services with full support for content negotiation using custom or built-in formatters (JSON, XML)

用完全受支持的,使用内置或自定义的json 格式化器 创建 自定义的 http 服务

  • Model Binding automatically maps data from HTTP requests to action method parameters
  • Model Validation automatically performs client and server side validation

Client-side development

ASP.NET Core is designed to integrate seamlessly with a variety of client-side frameworks, including AngularJS, KnockoutJS and Bootstrap.

Asp.net core 从设计上无缝集成了客户端开发 框架 ,包括:AngularJSKnockoutJSBootstrap

See Client-Side Development for more details.

Next steps


© Copyright 2016, Microsoft. Revision 406ff0d3.

                                         蒙

                                    2016-09-23  15:31  周五

        

                    

000.Introduction to ASP.NET Core--【Asp.net core 介绍】的更多相关文章

  1. .NET Core & ASP.NET Core 1.0在Redhat峰会上正式发布

    众所周知,Red Hat和微软正在努力使.NET Core成为Red Hat企业版Linux (RHEL)系统上的一流开发平台选项.这个团队已经一起工作好几个月了,RHEL对.NET有许多需求.今天在 ...

  2. ASP.NET Core - ASP.NET Core MVC 的功能划分

    概述 大型 Web 应用比小型 Web 应用需要更好的组织.在大型应用中,ASP.NET MVC(和 Core MVC)所用的默认组织结构开始成为你的负累.你可以使用两种简单的技术来更新组织方法并及时 ...

  3. .NET Core & ASP.NET Core 1.0

    .NET Core & ASP.NET Core 1.0在Redhat峰会上正式发布 众所周知,Red Hat和微软正在努力使.NET Core成为Red Hat企业版Linux (RHEL) ...

  4. asp.net core + mysql + ef core + linux

    asp.net core + mysql + ef core + linux 以前开发网站是针对windows平台,在iis上部署.由于这次需求的目标服务器是linux系统,就尝试用跨平台的.NET ...

  5. 003.ASP.NET Core tutorials--【Asp.net core 教程】

    ASP.NET Core tutorials Asp.net core 教程 2016-10-14 1 分钟阅读时长 本文内容 1.Building web applications 构建web应用 ...

  6. .Net Core 2.0生态(3):ASP.NET Core 2.0 特性介绍和使用指南

    ASP.NET Core 2.0 发布日期:2017年8月14日 ASP.NET团队宣布ASP.NET Core 2.0正式发布,发布Visual Studio 2017 15.3支持ASP.NET ...

  7. Asp.net Core中SignalR Core预览版的一些新特性前瞻,附源码(消息订阅与发送二进制数据)

    目录 SignalR系列目录(注意,是ASP.NET的目录.不是Core的) 前言 一晃一个月又过去了,上个月有个比较大的项目要验收上线.所以忙的脚不沾地.现在终于可以忙里偷闲,写一篇关于Signal ...

  8. ABP 教程文档 1-1 手把手引进门之 ASP.NET Core & Entity Framework Core(官方教程翻译版 版本3.2.5)

    本文是ABP官方文档翻译版,翻译基于 3.2.5 版本 官方文档分四部分 一. 教程文档 二.ABP 框架 三.zero 模块 四.其他(中文翻译资源) 本篇是第一部分的第一篇. 第一部分分三篇 1- ...

  9. 给外行或者刚入门普及一下关于C#,.NET Framework(.NET框架),.Net,CLR,ASP,ASP.Net, VS,以及.NET Core的概念

    一.概念 1. C# :C#是微软公司发布的一种面向对象的.运行于.NET Framework之上的高级程序设计语言. 2..NET Framework(.NET框架):.NET framework ...

随机推荐

  1. Solr的原理及在项目中的使用实例.

    前面已经讲过 如果安装及配置Solr服务器了, 那么现在我们就来正式在代码中使用Solr.1,这里Solr主要是怎么使用的呢?  当我们在前台页面搜索商品名称关键词时, 我们这时是在Solr库中去查找 ...

  2. 2013 duilib入门简明教程 -- 自绘控件 (15)

        在[2013 duilib入门简明教程 -- 复杂控件介绍 (13)]中虽然介绍了界面设计器上的所有控件,但是还有一些控件并没有被放到界面设计器上,还有一些常用控件duilib并没有提供(比如 ...

  3. java中集合类中Collection接口中的Map接口的常用方法熟悉

    1:Map接口提供了将键映射到值的对象.一个映射不能包含重复的键:每个键最多只能映射到一个值.Map接口中同样提供了集合的常用方法. 2:由于Map集合中的元素是通过key,value,进行存储的,要 ...

  4. python发送邮件及附件

    今天给大伙说说python发送邮件,官方的多余的话自己去百度好了,还有一大堆文档说实话不到万不得已的时候一般人都不会去看,回归主题: 本人是mac如果没有按照依赖模块的请按照下面的截图安装 导入模块如 ...

  5. 理解DOM事件流的三个阶段

    本文主要解决两个问题: 1.什么是事件流 2.DOM事件流的三个阶段 事件流之事件冒泡与事件捕获 在浏览器发展的过程中,开发团队遇到了一个问题.那就是页面中的哪一部分拥有特定的事件? 可以想象画在一张 ...

  6. 【开源】OSharp框架解说系列(1):总体设计及系列导航

    系列文章导航 [开源]OSharp框架解说系列(1):总体设计 [开源]OSharp框架解说系列(2.1):EasyUI的后台界面搭建及极致重构 [开源]OSharp框架解说系列(2.2):EasyU ...

  7. Notepad++使用小结

    还是那句话“工欲善其事必先利其器”用Notepad++也有一段时间了,也积累了一些东西,写篇博文与大家分享一下使用Notepad++的一些心得.  简单的说一下Notepad++是什么东西吧,Note ...

  8. Apache漏洞修复

    今天受同事的委托,修复一台服务器的Apache漏洞,主要集中在以下几点: 1.Apache httpd remote denial of service(中危) 修复建议:将Apache HTTP S ...

  9. 关于MVC EF架构及Repository模式的一点心得

    一直都想写博客,可惜真的太懒了或者对自己的描述水平不太自信,所以...一直都是不想写的状态,关于领域驱动的东西看了不少,但是由于自己水平太差加上工作中实在用不到,所以一直处于搁置状态,最近心血来潮突然 ...

  10. 安装nginx

    [yum安装nginx] yum clean all(这步不执行会出现no more mirrors to try错误) cd /etc/yum.repos.d/ vi nginx.repo 填写 [ ...