-
Notifications
You must be signed in to change notification settings - Fork 464
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add configuration extensions methods
- Loading branch information
support
committed
Dec 14, 2023
1 parent
a49cd4d
commit 7b157a0
Showing
4 changed files
with
65 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/Web/Grand.Web.Common/Extensions/ConfigurationExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using Grand.Infrastructure.Configuration; | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.AspNetCore.Http.Features; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace Grand.Web.Common.Extensions | ||
{ | ||
public static class ConfigurationExtensions | ||
{ | ||
|
||
public static void AddAppSettingsJsonFile(this IConfigurationManager configuration, string[] args) | ||
{ | ||
configuration.AddJsonFile("App_Data/appsettings.json"); | ||
configuration.AddEnvironmentVariables(); | ||
if (args.Any()) | ||
{ | ||
configuration.AddCommandLine(args); | ||
var appSettings = configuration["appsettings"]; | ||
if (!string.IsNullOrEmpty(appSettings)) | ||
{ | ||
configuration.AddJsonFile($"App_Data/{appSettings}/appsettings.json"); | ||
} | ||
} | ||
} | ||
public static void ConfigureApplicationSettings(this WebApplicationBuilder builder) | ||
{ | ||
//Allow non ASCII chars in headers | ||
var config = new AppConfig(); | ||
builder.Configuration.GetSection("Application").Bind(config); | ||
if (config.AllowNonAsciiCharInHeaders) | ||
{ | ||
builder.WebHost.ConfigureKestrel(options => | ||
{ | ||
options.ResponseHeaderEncodingSelector = _ => Encoding.UTF8; | ||
}); | ||
} | ||
if (config.MaxRequestBodySize.HasValue) | ||
{ | ||
builder.WebHost.ConfigureKestrel(host => | ||
{ | ||
host.Limits.MaxRequestBodySize = config.MaxRequestBodySize.Value; | ||
}); | ||
|
||
builder.Services.Configure<FormOptions>(opt => | ||
{ | ||
opt.MultipartBodyLengthLimit = config.MaxRequestBodySize.Value; | ||
}); | ||
|
||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters