Skip to content
Merged
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
19 changes: 18 additions & 1 deletion dotnet/src/dotnetcore/GxNetCoreStartup/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ public static void Main(string[] args)
if (args.Length > 3 && Uri.UriSchemeHttps.Equals(args[3], StringComparison.OrdinalIgnoreCase))
schema = Uri.UriSchemeHttps;
}
else
{
LocatePhysicalLocalPath();

}
if (port == DEFAULT_PORT)
{
BuildWebHost(null).Run();
Expand All @@ -66,10 +71,12 @@ public static void Main(string[] args)
Console.Read();
}
}

public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.ConfigureLogging(logging => logging.AddConsole())
.UseStartup<Startup>()
.UseContentRoot(Startup.LocalPath)
.Build();

public static IWebHost BuildWebHostPort(string[] args, string port)
Expand All @@ -82,8 +89,17 @@ static IWebHost BuildWebHostPort(string[] args, string port, string schema)
.ConfigureLogging(logging => logging.AddConsole())
.UseUrls($"{schema}://*:{port}")
.UseStartup<Startup>()
.UseContentRoot(Startup.LocalPath)
.Build();
}
private static void LocatePhysicalLocalPath()
{
string startup = FileUtil.GetStartupDirectory();
string startupParent = Directory.GetParent(startup).FullName;
if (startup == Startup.LocalPath && !File.Exists(Path.Combine(startup, Startup.APP_SETTINGS)) && File.Exists(Path.Combine(startupParent, Startup.APP_SETTINGS)))
Startup.LocalPath = startupParent;
}

}

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

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