手把手搭建一个ASP.NET Core Web应用程序(默认HTTPS协议)
作者:作者不详  发布日期:2020-03-12 11:21:03
  手把手搭建一个ASP.NET Core Web应用程序(默认HTTPS协议)

手把手搭建一个ASP.NET Core Web应用程序(默认HTTPS协议)


手把手搭建一个默认HTTPS协议的ASP.NET Core Web应用程序。

开发环境:VS2017。


操作步骤:

1. 打开VS,新建项目。Visual C#\Web\.NET Core\ASP.NET Core Web应用程序。

贴图图片-手把手搭建一个ASPNETCoreWeb应用程序1


2. 选择Web应用程序,勾选为HTTPS配置


贴图图片-手把手搭建一个ASPNETCoreWeb应用程序2


3. 自动生成的解决方案


贴图图片-手把手搭建一个ASPNETCoreWeb应用程序6


4. 运行解决方案,询问是否相信IIS Express SSL证书?勾选【不再询问】。点【是】。


贴图图片-手把手搭建一个ASPNETCoreWeb应用程序3


5. 为localhost安装默认的SSL证书。点【是】


贴图图片-手把手搭建一个ASPNETCoreWeb应用程序4


6. IIS运行默认站点。


贴图图片-手把手搭建一个ASPNETCoreWeb应用程序5




Program.cs文件内容:

C# Code:

public class Program
{
  
public static void Main(string[] args)
  {
    CreateWebHostBuilder(args).Build().Run();
  }
  
  
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
  WebHost.CreateDefaultBuilder(args)
  .UseStartup
<Startup>();
}

//来源:C/S框架网(www.csframework.com) QQ:23404761



Startup.cs文件内容:


C# Code:

public class Startup
{
  
public Startup(IConfiguration configuration)
  {
    Configuration
= configuration;
  }
  
  
public IConfiguration Configuration { get; }
  
  
// This method gets called by the runtime. Use this method to add services to the container.
  
public void ConfigureServices(IServiceCollection services)
  {
    services.Configure
<CookiePolicyOptions>(options =>
    {
      
// This lambda determines whether user consent for non-essential cookies is needed for a given request.
      
options.CheckConsentNeeded = context => true;
      options.MinimumSameSitePolicy
= SameSiteMode.None;
      });
      
      
      services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
    }
    
    
// 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();
      }
      
else
      {
        app.UseExceptionHandler(
"/Error");
        app.UseHsts();
      }
      
      app.UseHttpsRedirection();
      app.UseStaticFiles();
      app.UseCookiePolicy();
      
      app.UseMvc();
    }
  }
  
  
//来源:C/S框架网(www.csframework.com) QQ:23404761






扫一扫加微信:
 



上一篇 下一篇