2018年11月26日 星期一

asp.net core https

Ref: https://docs.microsoft.com/zh-tw/aspnet/core/security/enforcing-ssl?view=aspnetcore-2.1&tabs=visual-studio

1. ASUS X450J @ Windows 10 x64
2. Visual Studio 2017 (dotnet --version 2.1.403)
3. IP: 192.168.1.108
//-------------
4. dotnet new web -o https1   // create server template
5. Program.cs
//  add .UseUrls("http://192.168.1.108:5000/", "https://192.168.1.108:5001/")
6. Startup.cs
public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc(); // Add
        }

        // 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!");
                });
                -------------------------------*/
            // Ref: https://docs.microsoft.com/zh-tw/aspnet/core/security/enforcing-ssl?view=aspnetcore-2.1&tabs=visual-studio
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Error");
                app.UseHsts();
            }

            app.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseCookiePolicy();
            app.UseMvc();
        }
7. dotnet run // Testing

沒有留言:

張貼留言