1313using Microsoft . AspNetCore . DataProtection ;
1414using Microsoft . AspNetCore . Hosting ;
1515using Microsoft . AspNetCore . Http ;
16+ using Microsoft . AspNetCore . Http . Features ;
1617using Microsoft . AspNetCore . Mvc ;
1718using Microsoft . AspNetCore . Rewrite ;
1819using Microsoft . AspNetCore . Routing ;
1920using Microsoft . AspNetCore . Server . Kestrel . Core ;
2021using Microsoft . AspNetCore . StaticFiles ;
21- using Microsoft . Extensions . Configuration ;
2222using Microsoft . Extensions . DependencyInjection ;
2323using Microsoft . Extensions . FileProviders ;
2424using Microsoft . Extensions . Logging ;
@@ -90,6 +90,7 @@ public class Startup
9090
9191 static readonly ILog log = log4net . LogManager . GetLogger ( typeof ( Startup ) ) ;
9292 const int DEFAULT_SESSION_TIMEOUT_MINUTES = 20 ;
93+ const int DEFAULT_MAX_FILE_UPLOAD_SIZE_BYTES = 528000000 ;
9394 public static string VirtualPath = string . Empty ;
9495 public static string LocalPath = Directory . GetCurrentDirectory ( ) ;
9596
@@ -107,22 +108,14 @@ public class Startup
107108
108109 public Startup ( Microsoft . AspNetCore . Hosting . IHostingEnvironment env )
109110 {
110-
111- var builder = new ConfigurationBuilder ( )
112- . SetBasePath ( env . ContentRootPath )
113- . AddJsonFile ( "appsettings.json" , optional : false , reloadOnChange : true )
114- . AddJsonFile ( $ "appsettings.{ env . EnvironmentName } .json", optional : true )
115- . AddEnvironmentVariables ( ) ;
116111 GXRouting . ContentRootPath = env . ContentRootPath ;
117112 GXRouting . UrlTemplateControllerWithParms = "controllerWithParms" ;
118- Config . ConfigRoot = builder . Build ( ) ;
119113 GxContext . IsHttpContext = true ;
120114 gxRouting = new GXRouting ( REST_BASE_URL ) ;
121115 }
122116 public void ConfigureServices ( IServiceCollection services )
123117 {
124118 services . AddMvc ( option => option . EnableEndpointRouting = false ) ;
125- services . Configure < AppSettings > ( Config . ConfigRoot . GetSection ( "AppSettings" ) ) ;
126119 services . Configure < KestrelServerOptions > ( options =>
127120 {
128121 options . AllowSynchronousIO = true ;
@@ -133,17 +126,25 @@ public void ConfigureServices(IServiceCollection services)
133126 options . AllowSynchronousIO = true ;
134127 } ) ;
135128 services . AddDistributedMemoryCache ( ) ;
136- AppSettings settings = new AppSettings ( ) ;
137- Config . ConfigRoot . GetSection ( "AppSettings" ) . Bind ( settings ) ;
138129
130+ services . Configure < FormOptions > ( options =>
131+ {
132+ if ( Config . GetValueOf ( "MaxFileUploadSize" , out string MaxFileUploadSizeStr ) && int . TryParse ( MaxFileUploadSizeStr , out int MaxFileUploadSize ) )
133+ options . MultipartBodyLengthLimit = MaxFileUploadSize ;
134+ else
135+ options . MultipartBodyLengthLimit = DEFAULT_MAX_FILE_UPLOAD_SIZE_BYTES ;
136+ } ) ;
139137 ISessionService sessionService = GXSessionServiceFactory . GetProvider ( ) ;
140138
141139 if ( sessionService != null )
142140 ConfigureSessionService ( services , sessionService ) ;
143141 services . AddHttpContextAccessor ( ) ;
144142 services . AddSession ( options =>
145143 {
146- options . IdleTimeout = TimeSpan . FromMinutes ( settings . SessionTimeout == 0 ? DEFAULT_SESSION_TIMEOUT_MINUTES : settings . SessionTimeout ) ;
144+ if ( Config . GetValueOf ( "SessionTimeout" , out string SessionTimeoutStr ) && int . TryParse ( SessionTimeoutStr , out int SessionTimeout ) )
145+ options . IdleTimeout = TimeSpan . FromMinutes ( SessionTimeout ) ;
146+ else
147+ options . IdleTimeout = TimeSpan . FromMinutes ( DEFAULT_SESSION_TIMEOUT_MINUTES ) ;
147148 options . Cookie . HttpOnly = true ;
148149 options . Cookie . SecurePolicy = CookieSecurePolicy . SameAsRequest ;
149150 options . Cookie . IsEssential = true ;
0 commit comments