1.プロジェクトの確立
2.プロジェクトの構造
1.プロジェクト構造の説明
ルートディレクトリ/ファイル | 説明 |
---|---|
.vscodeディレクトリ | 同等.vs、.ideaフォルダがあるVSコードプロジェクトの設定ディレクトリ、 |
binディレクトリ | コンパイラの出力ディレクトリ |
OBJディレクトリ | 中間結果をコンパイルするコンパイラで設定を保存するための中間の設定ディレクトリをコンパイラ |
プロパティディレクトリ | 設定項目を格納するために使用されます |
wwwrootディレクトリ | 静的ファイルのディレクトリ、CSS、JS、写真や他のファイル |
helloweb.csprojファイル | 項目説明ファイル |
Program.csのファイル | アプリケーションのエントリ・クラス・ファイル |
Startup.csファイル | ASP.NETコアWebアプリケーションの起動クラスファイル、プロジェクトを開始する前に、使用する設定 |
3.スタートプロジェクト
私たちが代わりに直接IISのエクスプレスアプリケーションを選択したプロジェクト、開始するには[スタート]> [デバッグ-デバッグ:私達はちょうどF5、またはメニューを打つ
デフォルトのポートは5001でバインドASP.NETコアを、および2.1のデフォルト後HTTPS ASP.NETコアを拘束しましたプロジェクトの成功が始まった後、VSのコードは、私たちは、デフォルトのブラウザを開いて訪問するのに役立ちます。https://localhost:5001
4.バインディングプロトコルHTTPSはHTTPで変更し、設定ファイルを変更します
その後、我々はバインドされているHTTPSプロトコルを削除するには、設定を変更することができます
プロパティ/ launchSettings.jsonファイルを開くには、
{ "iisSettings": { "windowsAuthentication": false, "anonymousAuthentication": true, "iisExpress": { "applicationUrl": "http://localhost:6323", "sslPort": 44330 } }, "profiles": { "IIS Express": { "commandName": "IISExpress", "launchBrowser": true, "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } }, "Demo00BuildProject": { "commandName": "Project", "launchBrowser": true, "applicationUrl": "https://localhost:5001;http://localhost:5000", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } } } }
iisSettings、profiles.helloweb配置节点都有启动绑定配置,因为VS Code启动项目默认是不通过IIS来host的,iisSettings选项我们忽略即可。将applicationUrl修改为http://localhost:5001
然后重启项目(Ctrl+Shift+F5)机会看到干净纯洁的Hello World!
{ "profiles": { "Demo00BuildProject": { "commandName": "Project", "launchBrowser": true, "applicationUrl": "http://localhost:5001", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } } } }
修改后运行
4.项目启动简介
应用程序入口类,在应用启动的时候,会执行CreateWebHostBuilder方法,在这个方法中通过类Startup
创建了默认了HostBuilder
public class Program { public static void Main(string[] args) { CreateWebHostBuilder(args).Build().Run(); } public static IWebHostBuilder CreateWebHostBuilder(string[] args) => WebHost.CreateDefaultBuilder(args) .UseStartup<Startup>(); }
应用启动类,web项目模板默认在项目启动的时候调用IApplicationBuilder.run方法,在当前HTTP上下文(HttpContext)中输出了Hello World!,ConfigureService一般用于启动单例,配置,注入等过程,Configure时用户请求管道,用于解析处理用户的请求,mvc中间件,权限控制等过程在此处进行
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!"); }); } }
方法 | 说明 |
---|---|
ConfigureServices | 用于配置应用启动时加载的Service |
Configure | 用于配置HTTP请求管道 |
web项目模板默认在项目启动的时候调用IApplicationBuilder.run方法,在当前HTTP上下文(HttpContext)中输出了Hello World!
context.Response.WriteAsync(“Hello World!”);