-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
56 lines (50 loc) · 1.96 KB
/
Copy pathProgram.cs
File metadata and controls
56 lines (50 loc) · 1.96 KB
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
using System;
using System.Diagnostics;
using System.IO;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
namespace DevWebServer
{
public class Program
{
public static void Main(string[] args)
{
bool isDev = string.Equals(
Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT"),
Environments.Development,
StringComparison.OrdinalIgnoreCase);
if (!isDev)
{
// Manually set the current directory because when run from a context menu shortcut
// the content directory can be c:\windows\system32 which seems a tad unsafe
var pathToDll = "";
foreach (ProcessModule module in Process.GetCurrentProcess().Modules)
{
if (string.Equals(module.ModuleName, "devwebserver.dll", StringComparison.OrdinalIgnoreCase))
{
pathToDll = module.FileName;
break;
}
}
if (string.IsNullOrWhiteSpace(pathToDll))
{
throw new InvalidOperationException("Can't get the devwebserver.dll module path.");
}
var pathToContentRoot = Path.GetDirectoryName(pathToDll);
Directory.SetCurrentDirectory(pathToContentRoot);
}
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.ConfigureKestrel(serverOptions =>
{
// Set properties and call methods on options
serverOptions.AddServerHeader = false;
})
.UseStartup<Startup>();
});
}
}