ASP.NET CORE
最近開始著手把系統升級到2.1版本
會想把系統升級是因為能夠累積自己在.NET CORE升級經驗
因為2.1是長期支持版本,可以獲得更好品質,環境部分是NET Core 2.0 SDK - Microsoft.AspNetCore.All(2.0.6)
其實也希望提升自己的系統在商業的競爭力。
調整專案檔 .csproj
<TargetFramework>netcoreapp2.0</TargetFramework>
//改如下
<TargetFramework>netcoreapp2.1</TargetFramework>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.6" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="2.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.3" PrivateAssets="All" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.4" PrivateAssets="All" />
//改如下
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="2.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.1.1" PrivateAssets="All" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.1.1" PrivateAssets="All" />
最後把寫法調整改為 ASP.NET Core 2.1 的寫法
public static void Main(string[] args)
{
BuildWebHost(args).Run();
}
public static IWebHost BuildWebHost(string[] args)
{
var config = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("reportConfig.json", optional: false, reloadOnChange: true)
.Build();
return WebHost.CreateDefaultBuilder(args)
.UseConfiguration(config)
.UseStartup<Startup>()
.UseDefaultServiceProvider(options => options.ValidateScopes = false)
.Build();
}
//調整如下
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((hostingContext, config) =>
{
config.AddJsonFile("reportConfig.json", optional: false, reloadOnChange: true);
})
.UseStartup<Startup>()
.UseDefaultServiceProvider(options => options.ValidateScopes = false);
//新加
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
services.ConfigureApplicationCookie(options =>
{
options.ExpireTimeSpan = TimeSpan.FromMinutes(60);
if (env.IsDevelopment())
{
// 移除 app.UseBrowserLink();
app.UseDeveloperExceptionPage();
app.UseDatabaseErrorPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
//2.1
app.UseHsts();
}
app.Use(async (context, next) =>
}
return next(context);
});
//2.1
app.UseHttpsRedirection();
app.UseStaticFiles();
//2.1
app.UseCookiePolicy();
app.UseAuthentication();
目前改完之後,系統發佈到測試機,進行測試,找個時機點發布到正式機器,看有無狀況出現。
元哥的筆記