|
1 | 1 | using System.Data.Common;
|
2 | 2 | using System.Net.Http.Headers;
|
3 | 3 | using System.Reflection;
|
| 4 | +using System.Runtime.CompilerServices; |
4 | 5 | using Microsoft.AspNetCore.Builder;
|
5 | 6 | using Microsoft.AspNetCore.DataProtection.Infrastructure;
|
6 | 7 | using Microsoft.AspNetCore.Hosting;
|
@@ -326,12 +327,40 @@ public static IUmbracoBuilder AddHelpers(this IUmbracoBuilder builder)
|
326 | 327 | return builder;
|
327 | 328 | }
|
328 | 329 |
|
329 |
| - [Obsolete("This is not necessary any more. This will be removed in v17")] |
| 330 | + [Obsolete("This is not necessary any more. This will be removed in v16")] |
330 | 331 | public static IUmbracoBuilder AddWebServer(this IUmbracoBuilder builder)
|
331 | 332 | {
|
| 333 | + builder.Services.Configure<KestrelServerOptions>(options => |
| 334 | + { |
| 335 | + options.AllowSynchronousIO = true; |
| 336 | + }); |
| 337 | + |
| 338 | + try |
| 339 | + { |
| 340 | + // See https://github.com/umbraco/Umbraco-CMS/pull/17886. This is a workaround for non-windows machines |
| 341 | + // they won't have IIS available and trying to set this option will throw an exception. |
| 342 | + // |
| 343 | + // We're deferring this call to a method because if we just try to set the options here, we still get a |
| 344 | + // TypeLoadException on non-windows machines. |
| 345 | + // This workaround came from this comment: https://stackoverflow.com/a/3346975 |
| 346 | + AllowSynchronousIOForIIS(builder); |
| 347 | + } |
| 348 | + catch (TypeLoadException) |
| 349 | + { |
| 350 | + // Ignoring this exception because it's expected on non-windows machines |
| 351 | + } |
332 | 352 | return builder;
|
333 | 353 | }
|
334 | 354 |
|
| 355 | + // Prevents the compiler from inlining the method |
| 356 | + [MethodImpl(MethodImplOptions.NoInlining)] |
| 357 | + private static void AllowSynchronousIOForIIS(IUmbracoBuilder builder) => |
| 358 | + builder.Services.Configure<IISServerOptions>( |
| 359 | + options => |
| 360 | + { |
| 361 | + options.AllowSynchronousIO = true; |
| 362 | + }); |
| 363 | + |
335 | 364 | private static IProfiler GetWebProfiler(IConfiguration config, IHttpContextAccessor httpContextAccessor)
|
336 | 365 | {
|
337 | 366 | var isDebug = config.GetValue<bool>($"{Constants.Configuration.ConfigHosting}:Debug");
|
|
0 commit comments