索引:css
目錄索引html
Introduction to ASP.NET Corelinux
Asp.net core 介紹nginx
By Daniel Roth, Rick Anderson and Shaun Luttingit
Meng.Net 自譯github
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 youweb
Asp.net core 是 asp.net 的重大重構版本 , 本文介紹asp.net core新的概念,而且解釋你怎樣json
develop modern web apps.bootstrap
開發現代web 應用.windows
Sections:
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 上是開源的 .
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 你得到了 如下基本的改進:
一個 構建 web UI / web api 的統一模式
集成 現代的客戶端框架 及 開發流程
一個 基於雲的 環境配置系統
內嵌 依賴注入 DI
新的 輕量級的 / 模塊化 的 http 請求管道
能夠 宿主與iis 或者 自宿主
以 .net core 做爲基礎, 支持 並行 版本 控制
徹底以 nuget 包做爲承載
新的工具簡化現代web開發
編譯並跨平臺運行,在 windows/mac/linux 系統上
開源/開源社區,支持的
應用程序解析
An ASP.NET Core app is simply a console app that creates a web server in its Main method:
一個asp.net core 應用,是一個簡單的控制檯應用在它的main方法中建立的web服務.
1 using System; 2 using Microsoft.AspNetCore.Hosting; 3 4 namespace aspnetcoreapp 5 { 6 public class Program 7 { 8 public static void Main(string[] args) 9 { 10 var host = new WebHostBuilder() 11 .UseKestrel() 12 .UseStartup<Startup>() 13 .Build(); 14 15 host.Run(); 16 } 17 } 18 }
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 請求。
The UseStartup method on WebHostBuilder specifies the Startup class for your app.
WebHostBuilder 類 UseStartup() 方法使用你在程序中指定的 Startup 類。
1 public class Program 2 { 3 public static void Main(string[] args) 4 { 5 var host = new WebHostBuilder() 6 .UseKestrel() 7 .UseStartup<Startup>() 8 .Build(); 9 10 host.Run(); 11 } 12 }
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 的 ,而且包含下面兩個方法:
1 public class Startup 2 { 3 public void ConfigureServices(IServiceCollection services) 4 { 5 } 6 7 public void Configure(IApplicationBuilder app) 8 { 9 } 10 }
ConfigureServices() 定義了應用中須要的服務,如:ASP.NET MVC Core、Entity Framework Core、Identity 等等。
Core, Identity, etc.)
Configure() 定義了請求管道中的中間件。
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 。
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.
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 同樣。
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 指定。
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 中另外指定不一樣的路徑。
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, 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
用徹底受支持的,使用內置或自定義的json 格式化器 建立 自定義的 http 服務
ASP.NET Core is designed to integrate seamlessly with a variety of client-side frameworks, including AngularJS, KnockoutJS and Bootstrap.
Asp.net core 從設計上無縫集成了客戶端開發 框架 ,包括:AngularJS、KnockoutJS 、Bootstrap 。
See Client-Side Development for more details.
© Copyright 2016, Microsoft. Revision 406ff0d3.
蒙
2016-09-23 15:31 週五