• ASP.NET Core 中文文档 第一章 入门


    本文已更新,最后更新于2017年4月21日

    原文:Geting Started with ASP.NET Core
    译文:ASP.NET Core 入门
    翻译:娄宇(Lyrics)刘怡(AlexLEWIS)(修订)

    联系我们:
    QQ Group: 436035237 (dotNet Core Studying Group)
    GitHub Repo: https://github.com/dotnetcore/aspnetcore-doc-cn/


    以下为老翻译存档


    原文:Getting Started
    翻译:娄宇(Lyrics)
    校对:刘怡(AlexLEWIS)

    1、安装 .NET Core

    2、创建一个新的 .NET Core 项目:

    mkdir aspnetcoreapp
    cd aspnetcoreapp
    dotnet new
    

    3、编辑 project.json 文件,添加 Kestrel Http Server 包引用:

    {
      "version": "1.0.0-*",
      "buildOptions": {
        "emitEntryPoint": true
      },
      "dependencies": {
        "Microsoft.NETCore.App": {
          "type": "platform",
          "version": "1.0.0-rc2-3002702"
        },
        "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-rc2-final"
      },
      "frameworks": {
        "netcoreapp1.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、运行应用程序(dotnet run 命令在应用程序过期(配置或代码发生变更)时重新生成它):

    dotnet run
    

    8、浏览http://localhost:5000:

    DEMO 代码

    下一步

    • 用 Visual Studio 创建 ASP.NET Core MVC 应用程序
    • 用 Visual Studio Code 在 macOS 上创建首个 ASP.NET Core 应用程序
    • 用 Visual Studio 和 ASP.NET Core MVC 创建首个 Web API
    • 原理

    返回目录

    由于水平有限,错漏之处在所难免,欢迎大家批评指正,不胜感激,我们将及时修正。
    dotNet Core Studying Group:436035237
  • 相关阅读:
    angularJS CDN
    Python matplotlib 交互模式
    Selenium
    流程图
    Linux Shell脚本教程
    FTP没权限直接删除目录,写的一个小工具循环删除
    正则星号隐藏手机号码的后4位
    日志函数
    夺命雷公狗C/C++-----3---helloworld的诞生
    夺命雷公狗C/C++-----2---开发工具篇
  • 原文地址:https://www.cnblogs.com/dotNETCoreSG/p/aspnetcore-1-getting_started.html
Copyright © 2020-2023  润新知