ASP.NET Core (二):入門

來源:互聯網
上載者:User

標籤:

上一篇:ASP.NET Core(一):簡介

下一篇:(待續)

 

英文原版:Getting Started

1、 安裝 .NET Core

2、 建立 .NET Core 項目

在命令提示字元視窗輸入命令:

mkdir aspnetcoreappcd aspnetcoreappdotnet new

 

3、 更新 project.json 檔案,將 Kestrel HTTP 伺服器程式包作為依賴添加到檔案中

{  "version": "1.0.0-*",  "buildOptions": {    "debugType": "portable",    "emitEntryPoint": true  },  "dependencies": {},  "frameworks": {    "netcoreapp1.0": {      "dependencies": {        "Microsoft.NETCore.App": {          "type": "platform",          "version": "1.0.0"        },        "Microsoft.AspNetCore.Server.Kestrel": "1.0.0"      },      "imports": "dnxcore50"    }  }}

 

4、 還原程式包

在命令提示字元視窗輸入命令:

dotnet restore

 

5、 添加 Startup.cs 類檔案,定義請求處理邏輯

using System;using Microsoft.AspNetCore.Builder;using Microsoft.AspNetCore.Hosting;using Microsoft.AspNetCore.Http;namespace aspnetcoreapp{    public class Startup    {        public void Configure(IApplicationBuilder app)        {            app.Run(context =>            {                return context.Response.WriteAsync("Hello from ASP.NET Core!");            });        }    }}

 

6、 更新 Program.cs 檔案中的代碼以安裝和啟動 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();        }    }}

 

7、 運行應用程式(app)(如果dll已到期,dotnet run 命令將重新build應用程式)

dotnet run

 

8、 在瀏覽器中瀏覽:http://localhost:5000

 

 

上一篇:ASP.NET Core(一):簡介

下一篇:(待續)

                                                 

ASP.NET Core (二):入門

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.