Skip to content
This repository has been archived by the owner on Mar 9, 2020. It is now read-only.

Migrated SampleWebApp.Core to .NET Core 3.1 LTS. #626

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions SampleWebApp.Core/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ namespace SampleWebApp.Core.Controllers
public class HomeController : Controller
{
private const string XlsxContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
private readonly IHostingEnvironment _hostingEnvironment;
private readonly IWebHostEnvironment _webHostEnvironment;

public HomeController(IHostingEnvironment hostingEnvironment)
public HomeController(IWebHostEnvironment webHostEnvironment)
{
_hostingEnvironment = hostingEnvironment;
_webHostEnvironment = webHostEnvironment;
}

/// <summary>
Expand All @@ -31,7 +31,7 @@ public IActionResult FileReport()

using (var package = createExcelPackage())
{
package.SaveAs(new FileInfo(Path.Combine(_hostingEnvironment.WebRootPath, reportsFolder, fileDownloadName)));
package.SaveAs(new FileInfo(Path.Combine(_webHostEnvironment.WebRootPath, reportsFolder, fileDownloadName)));
}
return File($"~/{reportsFolder}/{fileDownloadName}", XlsxContentType, fileDownloadName);
}
Expand Down Expand Up @@ -62,7 +62,7 @@ public IActionResult ReadFile()
{
var fileDownloadName = "report.xlsx";
var reportsFolder = "reports";
var fileInfo = new FileInfo(Path.Combine(_hostingEnvironment.WebRootPath, reportsFolder, fileDownloadName));
var fileInfo = new FileInfo(Path.Combine(_webHostEnvironment.WebRootPath, reportsFolder, fileDownloadName));
if (!fileInfo.Exists)
{
using (var package = createExcelPackage())
Expand Down Expand Up @@ -207,7 +207,7 @@ private ExcelPackage createExcelPackage()
worksheet.Cells[1, 1, 4, 4].AutoFitColumns();

worksheet.HeaderFooter.OddFooter.InsertPicture(
new FileInfo(Path.Combine(_hostingEnvironment.WebRootPath, "images", "captcha.jpg")),
new FileInfo(Path.Combine(_webHostEnvironment.WebRootPath, "images", "captcha.jpg")),
PictureAlignment.Right);

return package;
Expand Down
14 changes: 8 additions & 6 deletions SampleWebApp.Core/Program.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
using System.IO;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;

namespace SampleWebApp.Core
{
public class Program
{
public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.Build();
var host = CreateHostBuilder(args).Build();

host.Run();
}

public static IHostBuilder CreateHostBuilder(string[] args)
{
return Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder => webBuilder.UseStartup<Startup>());
}
}
}
10 changes: 5 additions & 5 deletions SampleWebApp.Core/SampleWebApp.Core.csproj
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
<ApplicationIcon />
<OutputType>Exe</OutputType>
<StartupObject />
</PropertyGroup>
<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.2.8" />
</ItemGroup>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\EPPlus\EPPlus.MultiTarget.csproj" />
</ItemGroup>
Expand Down
17 changes: 13 additions & 4 deletions SampleWebApp.Core/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,24 @@ public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddControllersWithViews();
}

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseDeveloperExceptionPage();
app.UseMvcWithDefaultRoute();
app.UseDefaultFiles();

app.UseHttpsRedirection();
app.UseStaticFiles();

app.UseRouting();

app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
});
}
}
}