起步

  1. Install .NET Core
  2. 安装 .NET Core
  3. Create a new .NET Core project:
  4. 创建一个新的 .NET Core 项目 mkdir aspnetcoreapp cd aspnetcoreapp dotnet new

  5. Update the project.json file to add the Kestrel HTTP server package as a dependency:

  6. 更新 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"
           }
        }
    

    }

  7. Restore the packages:

  8. 还原包 dotnet restore

  9. Add a Startup.cs file that defines the request handling logic:

  10. 添加一个定义处理请求逻辑的 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!"); 
               }); 
           } 
       } 
    

    }

  11. Update the code in Program.cs to setup and start the Web host:

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();
          }
      }
  }
  1. Run the app (the dotnet run command will build the app when it’s out of date):

7.启动应用(dotnet run命令会在应用过期的时候重新生成)

  dotnet run
  1. Browse to http://localhost:5000:

8.打开浏览器并浏览 http://localhost:5000

results matching ""

    No results matching ""