(2).net core web

 

建立一個空web應用web

dotnet new web -n myweb

 

1.appsettings.json : 配置文件json

{
  "Logging": {
    "LogLevel": {
      "Default": "Warning"
    }
  },
  "AllowedHosts": "*"
}

 

2.Program :main函數的所在地app

        public static void Main(string[] args)
        {
            CreateWebHostBuilder(args).Build().Run();
        }

        public static IWebHostBuilder CreateWebHostBuilder(string[] args)
        {
          return  WebHost.CreateDefaultBuilder(args).UseStartup<Startup>();
        }

 

3.Startup:async

    public class Startup
    {
        public void ConfigureServices(IServiceCollection services)
        {
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.Run(async (context) =>
            {
                await context.Response.WriteAsync("Hello World!");
            });
        }
    }

 

ConfigureServices方法用來用來添加服務的集合函數

 

Configure 中間件組件組成的請求處理管道ui

相關文章
相關標籤/搜索