当前位置: 移动技术网 > IT编程>开发语言>.net > ASP.NET Core:入门学习

ASP.NET Core:入门学习

2018年09月29日  | 移动技术网IT编程  | 我要评论

金正昆讲礼仪全集,小精宝,孙圳个人资料

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()
                .build();

            host.run();
        }
    }
}

7、 运行应用程序(app)(如果dll已过期,dotnet run 命令将重新build应用程序)

dotnet run

8、 在中浏览:https://localhost:5000

asp.net core 应用程序入门效果图

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网