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
39 changes: 26 additions & 13 deletions dotnet/src/dotnetcore/GxNetCoreStartup/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ public class Startup
const string CORS_ANY_ORIGIN = "*";
const double CORS_MAX_AGE_SECONDS = 86400;
internal const string GX_CONTROLLERS = "gxcontrollers";
internal static string DefaultFileName { get; set; }

public List<string> servicesBase = new List<string>();

Expand Down Expand Up @@ -530,10 +531,6 @@ public void Configure(IApplicationBuilder app, Microsoft.AspNetCore.Hosting.IHos
app.UseHttpsRedirection();
app.UseHsts();
}
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});

if (log.IsCriticalEnabled && env.IsDevelopment())
{
Expand Down Expand Up @@ -621,10 +618,13 @@ public void Configure(IApplicationBuilder app, Microsoft.AspNetCore.Hosting.IHos
routes.MapRoute($"{restBasePath}{{*{UrlTemplateControllerWithParms}}}", new RequestDelegate(gxRouting.ProcessRestRequest));
});
}
app.UseMvc(routes =>
if (FindAndStoreDefaultFile())
{
routes.MapRoute("Default", VirtualPath, new { controller = "Home", action = "Index" });
});
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute("Default", VirtualPath, new { controller = "Home", action = "Index" });
});
}

app.UseWebSockets();
string basePath = string.IsNullOrEmpty(VirtualPath) ? string.Empty : $"/{VirtualPath}";
Expand All @@ -647,6 +647,21 @@ private void ConfigureCors(IApplicationBuilder app)
app.UseCors(CORS_POLICY_NAME);
}
}
private static bool FindAndStoreDefaultFile()
{
string[] defaultFiles = { "default.htm", "default.html", "index.htm", "index.html" };
foreach (string file in defaultFiles)
{
string filePath = Path.Combine(LocalPath, file);
if (File.Exists(filePath))
{
DefaultFileName = file;
return true;
}
}
DefaultFileName = null;
return false;
}

private void ConfigureSwaggerUI(IApplicationBuilder app, string baseVirtualPath)
{
Expand Down Expand Up @@ -762,13 +777,11 @@ public class HomeController : Controller
{
public IActionResult Index()
{
string[] defaultFiles = { "default.htm", "default.html", "index.htm", "index.html" };
foreach (string file in defaultFiles) {
if (System.IO.File.Exists(Path.Combine(Startup.LocalPath, file))){
return Redirect(Url.Content($"~/{file}"));
}
if (!string.IsNullOrEmpty(Startup.DefaultFileName))
{
return Redirect(Url.Content($"~/{Startup.DefaultFileName}"));
}
return Redirect(defaultFiles[0]);
return NotFound();
}
}
internal class SetRoutePrefix : IApplicationModelConvention
Expand Down
Loading