-
Notifications
You must be signed in to change notification settings - Fork 2
/
WebFormsStartup.cs
72 lines (63 loc) · 2.17 KB
/
WebFormsStartup.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Threading;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Server.Kestrel;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using WebFormsHost.Hosting;
namespace WebFormsHost
{
public class WebFormsStartup : MarshalByRefObject
{
public WebFormsStartup()
{
}
public void Start(string contentRoot) {
// need to know the VPath ahead of time and the physical path ahead of time for the WF AppDomain
// need to figure out the hosting
IWebHost host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(contentRoot)
.ConfigureLogging((hostingContext, logging) =>
{
logging.AddConsole();
logging.AddFilter("System", LogLevel.Debug);
logging.AddFilter("Default", LogLevel.Debug);
})
.UseStartup<Startup>()
.Build();
host.Run();
}
}
public class Startup
{
private static readonly byte[] _helloWorldBytes = System.Text.Encoding.UTF8.GetBytes("Hello, World!");
private ILogger _log;
public Startup(ILoggerFactory factory)
{
_log = factory.CreateLogger("Steve");
}
public void ConfigureServices(IServiceCollection services)
{
services.AddWebForms();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
app.UseWebForms(env);
var appLifetime = app.ApplicationServices.GetRequiredService<IApplicationLifetime>();
appLifetime.ApplicationStopping.Register(
() => { OnShutdown(app.ApplicationServices.GetService<WebFormsApplicationServer>()); }
);
}
private void OnShutdown(WebFormsApplicationServer server)
{
server.Stop();
}
}
}