時(shí)間:2023-04-21 11:00:02 | 來(lái)源:網(wǎng)站運(yùn)營(yíng)
時(shí)間:2023-04-21 11:00:02 來(lái)源:網(wǎng)站運(yùn)營(yíng)
[Asp.Net Core] 系列教程 (二):using Microsoft.AspNetCore.Builder;using Microsoft.AspNetCore.Hosting;using Microsoft.AspNetCore.Http;using Microsoft.Extensions.DependencyInjection;using System;using System.Collections.Generic;using System.Linq;using System.Threading.Tasks;namespace One{ public class Startup { // This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 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!"); }); } }}
Startup 類可以用來(lái)定義HTTP請(qǐng)求處理管道和配置應(yīng)用程序需要的服務(wù)。//定義應(yīng)用程序所需要的服務(wù),例如 ASP.NET Core MVC、Entity Framework Core 和 Identity 等public void ConfigureServices(IServiceCollection services){}
//定義請(qǐng)求管道中的中間件,該方法可以用來(lái)定義我們的應(yīng)用程序如何響應(yīng)請(qǐng)求public void Configure(IApplicationBuilder app, IHostingEnvironment env){}
如果我們希望應(yīng)用程序的有不同的行為,我們就需要在 Configure() 方法中添加其他代碼來(lái)更改管道。app.Run(async (context) =>{ await context.Response.WriteAsync("Hello World!");});
我們也可以更改其內(nèi)容,例如:app.Run(async (context) =>{ await context.Response.WriteAsync("Hello EggMo!");});
那么應(yīng)用啟動(dòng)后顯示的響應(yīng)就是:關(guān)鍵詞:教程,系列
客戶&案例
營(yíng)銷資訊
關(guān)于我們
客戶&案例
營(yíng)銷資訊
關(guān)于我們
微信公眾號(hào)
版權(quán)所有? 億企邦 1997-2025 保留一切法律許可權(quán)利。