ASP.NET Core (二):入门_.NET_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > .NET > ASP.NET Core (二):入门

ASP.NET Core (二):入门

 2016/7/9 5:30:58  蠕毛虫  程序员俱乐部  我要评论(0)
  • 摘要:上一篇:ASP.NETCore(一):简介下一篇:(待续)英文原版:GettingStarted1、安装.NETCore2、创建.NETCore项目在命令提示符窗口输入命令:mkdiraspnetcoreappcdaspnetcoreappdotnetnew3、更新project.json文件,将KestrelHTTP服务器程序包作为依赖添加到文件中{"version":"1.0.0-*","buildOptions":{"debugType":"portable"
  • 标签:.net ASP.NET net

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

下一篇:(待续)

 

英文原版:Getting Started

1、 安装 .NET Core

2、 创建 .NET Core 项目

在命令提示符窗口输入命令:

mkdir aspnetcoreapp

cd aspnetcoreapp

dotnet 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(一):简介

下一篇:(待续)

                                                 

发表评论
用户名: 匿名