Skip to content

Commit

Permalink
Upgrade to ASP.NET Core 3.
Browse files Browse the repository at this point in the history
  • Loading branch information
CXuesong committed Jun 20, 2020
1 parent 4c66294 commit 1bad715
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 33 deletions.
19 changes: 9 additions & 10 deletions WebTestApplication/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,23 @@
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;

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

host.Run();
CreateHostBuilder(args).Build().Run();
}

public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
}
37 changes: 20 additions & 17 deletions WebTestApplication/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,51 +4,54 @@
using System.Reflection;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.AspNetCore.Hosting;
using JsonRpc.AspNetCore;
using Microsoft.AspNetCore.Http;

namespace WebTestApplication
{
public class Startup
{
public Startup(IHostingEnvironment env)
public Startup(IConfiguration configuration)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
.AddEnvironmentVariables();
Configuration = builder.Build();
Configuration = configuration;
}

public IConfigurationRoot Configuration { get; }
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)
{
// Add framework services.
services.AddMvc();
services.AddMemoryCache();
services.AddSession();
services.AddDistributedMemoryCache();
services.AddSession(options =>
{
options.IdleTimeout = TimeSpan.FromSeconds(300);
options.Cookie.HttpOnly = true;
options.Cookie.IsEssential = true;
});
services.AddControllers();

services.AddJsonRpc(options => options.UseCamelCaseContractResolver()).RegisterFromAssembly<Startup>();
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseSession();
// If you want to implement your JSON-RPC endpoint in Controller, you need to ensure calling
// UseWebSockets first, then UseMvc.
// UseWebSockets first, then UseEndpoints/UseMvc.
// You may also create your JSON-RPC Websocket endpoint with app.Use(...) rather than Controller.
// See https://docs.microsoft.com/en-us/aspnet/core/fundamentals/websockets?view=aspnetcore-2.2#how-to-use-websockets
// for more information.
app.UseWebSockets();
app.UseMvc();

app.UseJsonRpc("/api/jsonrpc");
app.UseRouting();
app.UseEndpoints(endpoints => {
endpoints.MapControllers();
});
app.UseStaticFiles();
}
}
Expand Down
7 changes: 1 addition & 6 deletions WebTestApplication/WebTestApplication.csproj
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.6.1" />
<PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Session" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.WebSockets" Version="2.2.1" />
</ItemGroup>
<ItemGroup>
<None Include="wwwroot\index.html" />
Expand Down

0 comments on commit 1bad715

Please sign in to comment.