Skip to content

Commit e37109b

Browse files
Support starting GxNetCoreStartup.exe with double click on web\bin directory (#758)
* Support starting GxNetCoreStartup.exe with double click on web\bin directory. * Setup ContentRoot also so appsettings.json is found.
1 parent e442f6e commit e37109b

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

dotnet/src/dotnetcore/GxNetCoreStartup/Startup.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ public static void Main(string[] args)
5050
if (args.Length > 3 && Uri.UriSchemeHttps.Equals(args[3], StringComparison.OrdinalIgnoreCase))
5151
schema = Uri.UriSchemeHttps;
5252
}
53+
else
54+
{
55+
LocatePhysicalLocalPath();
56+
57+
}
5358
if (port == DEFAULT_PORT)
5459
{
5560
BuildWebHost(null).Run();
@@ -66,10 +71,12 @@ public static void Main(string[] args)
6671
Console.Read();
6772
}
6873
}
74+
6975
public static IWebHost BuildWebHost(string[] args) =>
7076
WebHost.CreateDefaultBuilder(args)
7177
.ConfigureLogging(logging => logging.AddConsole())
7278
.UseStartup<Startup>()
79+
.UseContentRoot(Startup.LocalPath)
7380
.Build();
7481

7582
public static IWebHost BuildWebHostPort(string[] args, string port)
@@ -82,8 +89,17 @@ static IWebHost BuildWebHostPort(string[] args, string port, string schema)
8289
.ConfigureLogging(logging => logging.AddConsole())
8390
.UseUrls($"{schema}://*:{port}")
8491
.UseStartup<Startup>()
92+
.UseContentRoot(Startup.LocalPath)
8593
.Build();
8694
}
95+
private static void LocatePhysicalLocalPath()
96+
{
97+
string startup = FileUtil.GetStartupDirectory();
98+
string startupParent = Directory.GetParent(startup).FullName;
99+
if (startup == Startup.LocalPath && !File.Exists(Path.Combine(startup, Startup.APP_SETTINGS)) && File.Exists(Path.Combine(startupParent, Startup.APP_SETTINGS)))
100+
Startup.LocalPath = startupParent;
101+
}
102+
87103
}
88104

89105
public static class GXHandlerExtensions
@@ -108,6 +124,7 @@ public class Startup
108124
const long DEFAULT_MAX_FILE_UPLOAD_SIZE_BYTES = 528000000;
109125
public static string VirtualPath = string.Empty;
110126
public static string LocalPath = Directory.GetCurrentDirectory();
127+
internal static string APP_SETTINGS = "appsettings.json";
111128

112129
const string UrlTemplateControllerWithParms = "controllerWithParms";
113130
const string RESOURCES_FOLDER = "Resources";
@@ -348,7 +365,7 @@ public void Configure(IApplicationBuilder app, Microsoft.AspNetCore.Hosting.IHos
348365
OnPrepareResponse = s =>
349366
{
350367
var path = s.Context.Request.Path;
351-
if (path.HasValue && path.Value.IndexOf("/appsettings.json", StringComparison.OrdinalIgnoreCase)>=0)
368+
if (path.HasValue && path.Value.IndexOf($"/{APP_SETTINGS}", StringComparison.OrdinalIgnoreCase)>=0)
352369
{
353370
s.Context.Response.StatusCode = 401;
354371
s.Context.Response.Body = Stream.Null;

0 commit comments

Comments
 (0)