11using System ;
22using System . Collections . Generic ;
33using System . IO ;
4- using System . Reflection ;
54using System . Net ;
65using System . Threading . Tasks ;
76using GeneXus . Configuration ;
87using GeneXus . Http ;
98using GeneXus . HttpHandlerFactory ;
109using GeneXus . Services ;
1110using GeneXus . Utils ;
12- using GxClasses . Helpers ;
1311using GxClasses . Web . Middleware ;
1412using log4net ;
1513using Microsoft . AspNetCore ;
1816using Microsoft . AspNetCore . Diagnostics ;
1917using Microsoft . AspNetCore . Hosting ;
2018using Microsoft . AspNetCore . Http ;
19+ using Microsoft . AspNetCore . Http . Features ;
2120using Microsoft . AspNetCore . Mvc ;
2221using Microsoft . AspNetCore . Rewrite ;
2322using Microsoft . AspNetCore . Routing ;
2423using Microsoft . AspNetCore . Server . Kestrel . Core ;
2524using Microsoft . AspNetCore . StaticFiles ;
26- using Microsoft . Extensions . Configuration ;
2725using Microsoft . Extensions . DependencyInjection ;
2826using Microsoft . Extensions . FileProviders ;
2927using Microsoft . Extensions . Logging ;
@@ -95,6 +93,7 @@ public class Startup
9593
9694 static readonly ILog log = log4net . LogManager . GetLogger ( typeof ( Startup ) ) ;
9795 const int DEFAULT_SESSION_TIMEOUT_MINUTES = 20 ;
96+ const int DEFAULT_MAX_FILE_UPLOAD_SIZE_BYTES = 528000000 ;
9897 public static string VirtualPath = string . Empty ;
9998 public static string LocalPath = Directory . GetCurrentDirectory ( ) ;
10099
@@ -115,22 +114,14 @@ public class Startup
115114
116115 public Startup ( Microsoft . AspNetCore . Hosting . IHostingEnvironment env )
117116 {
118-
119- var builder = new ConfigurationBuilder ( )
120- . SetBasePath ( env . ContentRootPath )
121- . AddJsonFile ( "appsettings.json" , optional : false , reloadOnChange : true )
122- . AddJsonFile ( $ "appsettings.{ env . EnvironmentName } .json", optional : true )
123- . AddEnvironmentVariables ( ) ;
124117 GXRouting . ContentRootPath = env . ContentRootPath ;
125118 GXRouting . UrlTemplateControllerWithParms = "controllerWithParms" ;
126- Config . ConfigRoot = builder . Build ( ) ;
127119 GxContext . IsHttpContext = true ;
128120 gxRouting = new GXRouting ( REST_BASE_URL ) ;
129121 }
130122 public void ConfigureServices ( IServiceCollection services )
131123 {
132124 services . AddMvc ( option => option . EnableEndpointRouting = false ) ;
133- services . Configure < AppSettings > ( Config . ConfigRoot . GetSection ( "AppSettings" ) ) ;
134125 services . Configure < KestrelServerOptions > ( options =>
135126 {
136127 options . AllowSynchronousIO = true ;
@@ -141,17 +132,25 @@ public void ConfigureServices(IServiceCollection services)
141132 options . AllowSynchronousIO = true ;
142133 } ) ;
143134 services . AddDistributedMemoryCache ( ) ;
144- AppSettings settings = new AppSettings ( ) ;
145- Config . ConfigRoot . GetSection ( "AppSettings" ) . Bind ( settings ) ;
146135
136+ services . Configure < FormOptions > ( options =>
137+ {
138+ if ( Config . GetValueOf ( "MaxFileUploadSize" , out string MaxFileUploadSizeStr ) && int . TryParse ( MaxFileUploadSizeStr , out int MaxFileUploadSize ) )
139+ options . MultipartBodyLengthLimit = MaxFileUploadSize ;
140+ else
141+ options . MultipartBodyLengthLimit = DEFAULT_MAX_FILE_UPLOAD_SIZE_BYTES ;
142+ } ) ;
147143 ISessionService sessionService = GXSessionServiceFactory . GetProvider ( ) ;
148144
149145 if ( sessionService != null )
150146 ConfigureSessionService ( services , sessionService ) ;
151147 services . AddHttpContextAccessor ( ) ;
152148 services . AddSession ( options =>
153149 {
154- options . IdleTimeout = TimeSpan . FromMinutes ( settings . SessionTimeout == 0 ? DEFAULT_SESSION_TIMEOUT_MINUTES : settings . SessionTimeout ) ;
150+ if ( Config . GetValueOf ( "SessionTimeout" , out string SessionTimeoutStr ) && int . TryParse ( SessionTimeoutStr , out int SessionTimeout ) )
151+ options . IdleTimeout = TimeSpan . FromMinutes ( SessionTimeout ) ;
152+ else
153+ options . IdleTimeout = TimeSpan . FromMinutes ( DEFAULT_SESSION_TIMEOUT_MINUTES ) ;
155154 options . Cookie . HttpOnly = true ;
156155 options . Cookie . SecurePolicy = CookieSecurePolicy . SameAsRequest ;
157156 options . Cookie . IsEssential = true ;
0 commit comments