/// <summary>
        /// Adds tenant level configuration to serve static files from modules
        /// </summary>
        private static void AddStaticFiles(OrchardCoreBuilder builder)
        {
            builder.Configure((app, routes, serviceProvider) =>
            {
                var env = serviceProvider.GetRequiredService <IHostingEnvironment>();

                IFileProvider fileProvider;
                if (env.IsDevelopment())
                {
                    var fileProviders = new List <IFileProvider>();
                    fileProviders.Add(new ModuleProjectStaticFileProvider(env));
                    fileProviders.Add(new ModuleEmbeddedStaticFileProvider(env));
                    fileProvider = new CompositeFileProvider(fileProviders);
                }
                else
                {
                    fileProvider = new ModuleEmbeddedStaticFileProvider(env);
                }

                app.UseStaticFiles(new StaticFileOptions
                {
                    RequestPath  = "",
                    FileProvider = fileProvider
                });
            });
        }
Esempio n. 2
0
        /// <summary>
        /// Adds tenant level configuration to serve static files from modules
        /// </summary>
        private static void AddStaticFiles(OrchardCoreBuilder builder)
        {
            builder.Configure((app, routes, serviceProvider) =>
            {
                var env        = serviceProvider.GetRequiredService <IHostingEnvironment>();
                var appContext = serviceProvider.GetRequiredService <IApplicationContext>();

                IFileProvider fileProvider;
                if (env.IsDevelopment())
                {
                    var fileProviders = new List <IFileProvider>();
                    fileProviders.Add(new ModuleProjectStaticFileProvider(appContext));
                    fileProviders.Add(new ModuleEmbeddedStaticFileProvider(appContext));
                    fileProvider = new CompositeFileProvider(fileProviders);
                }
                else
                {
                    fileProvider = new ModuleEmbeddedStaticFileProvider(appContext);
                }

                var options = serviceProvider.GetRequiredService <IOptions <StaticFileOptions> >().Value;

                options.RequestPath  = "";
                options.FileProvider = fileProvider;
                app.UseStaticFiles(options);
            });
        }
Esempio n. 3
0
        /// <summary>
        /// Adds tenant level configuration to serve static files from modules
        /// </summary>
        private static void AddStaticFiles(OrchardCoreBuilder builder)
        {
            builder.ConfigureServices(services =>
            {
                services.AddSingleton <IModuleStaticFileProvider>(serviceProvider =>
                {
                    var env        = serviceProvider.GetRequiredService <IHostEnvironment>();
                    var appContext = serviceProvider.GetRequiredService <IApplicationContext>();

                    IModuleStaticFileProvider fileProvider;
                    if (env.IsDevelopment())
                    {
                        var fileProviders = new List <IStaticFileProvider>
                        {
                            new ModuleProjectStaticFileProvider(appContext),
                            new ModuleEmbeddedStaticFileProvider(appContext)
                        };
                        fileProvider = new ModuleCompositeStaticFileProvider(fileProviders);
                    }
                    else
                    {
                        fileProvider = new ModuleEmbeddedStaticFileProvider(appContext);
                    }
                    return(fileProvider);
                });

                services.AddSingleton <IStaticFileProvider>(serviceProvider =>
                {
                    return(serviceProvider.GetRequiredService <IModuleStaticFileProvider>());
                });
            });

            builder.Configure((app, routes, serviceProvider) =>
            {
                var fileProvider = serviceProvider.GetRequiredService <IModuleStaticFileProvider>();

                var options = serviceProvider.GetRequiredService <IOptions <StaticFileOptions> >().Value;

                options.RequestPath  = "";
                options.FileProvider = fileProvider;

                var shellConfiguration = serviceProvider.GetRequiredService <IShellConfiguration>();

                var cacheControl = shellConfiguration.GetValue("StaticFileOptions:CacheControl", "public, max-age=2592000, s-max-age=31557600");

                // Cache static files for a year as they are coming from embedded resources and should not vary
                options.OnPrepareResponse = ctx =>
                {
                    ctx.Context.Response.Headers[HeaderNames.CacheControl] = cacheControl;
                };

                app.UseStaticFiles(options);
            });
        }
 private static void AddStaticFiles(OrchardCoreBuilder builder)
 {
     stackVariable0 = builder;
     stackVariable1 = Microsoft.Extensions.DependencyInjection.ServiceCollectionExtensions.u003cu003ec.u003cu003e9__5_0;
     if (stackVariable1 == null)
     {
         dummyVar0      = stackVariable1;
         stackVariable1 = new Action <IServiceCollection>(Microsoft.Extensions.DependencyInjection.ServiceCollectionExtensions.u003cu003ec.u003cu003e9.u003cAddStaticFilesu003eb__5_0);
         Microsoft.Extensions.DependencyInjection.ServiceCollectionExtensions.u003cu003ec.u003cu003e9__5_0 = stackVariable1;
     }
     dummyVar1      = stackVariable0.ConfigureServices(stackVariable1, 0);
     stackVariable4 = builder;
     stackVariable5 = Microsoft.Extensions.DependencyInjection.ServiceCollectionExtensions.u003cu003ec.u003cu003e9__5_1;
     if (stackVariable5 == null)
     {
         dummyVar2      = stackVariable5;
         stackVariable5 = new Action <IApplicationBuilder, IEndpointRouteBuilder, IServiceProvider>(Microsoft.Extensions.DependencyInjection.ServiceCollectionExtensions.u003cu003ec.u003cu003e9.u003cAddStaticFilesu003eb__5_1);
         Microsoft.Extensions.DependencyInjection.ServiceCollectionExtensions.u003cu003ec.u003cu003e9__5_1 = stackVariable5;
     }
     dummyVar3 = stackVariable4.Configure(stackVariable5, 0);
     return;
 }
        /// <summary>
        /// Adds tenant level configuration to serve static files from modules
        /// </summary>
        private static void AddStaticFiles(OrchardCoreBuilder builder)
        {
            builder.ConfigureServices(services =>
            {
                services.AddSingleton <IModuleStaticFileProvider>(serviceProvider =>
                {
                    var env        = serviceProvider.GetRequiredService <IHostEnvironment>();
                    var appContext = serviceProvider.GetRequiredService <IApplicationContext>();

                    IModuleStaticFileProvider fileProvider;
                    if (env.IsDevelopment())
                    {
                        var fileProviders = new List <IStaticFileProvider>
                        {
                            new ModuleProjectStaticFileProvider(appContext),
                            new ModuleEmbeddedStaticFileProvider(appContext)
                        };
                        fileProvider = new ModuleCompositeStaticFileProvider(fileProviders);
                    }
                    else
                    {
                        fileProvider = new ModuleEmbeddedStaticFileProvider(appContext);
                    }
                    return(fileProvider);
                });

                services.AddSingleton <IStaticFileProvider>(serviceProvider =>
                {
                    return(serviceProvider.GetRequiredService <IModuleStaticFileProvider>());
                });
            });

            builder.Configure((app, routes, serviceProvider) =>
            {
                var fileProvider = serviceProvider.GetRequiredService <IModuleStaticFileProvider>();

                var shellConfiguration = serviceProvider.GetRequiredService <IShellConfiguration>();
                // Cache static files for a year as they are coming from embedded resources and should not vary.
                var cacheControl = shellConfiguration.GetValue("StaticFileOptions:CacheControl", $"public, max-age={TimeSpan.FromDays(30).TotalSeconds}, s-maxage={TimeSpan.FromDays(365.25).TotalSeconds}");

                // Use the current options values but without mutating the resolved instance.
                var options = serviceProvider.GetRequiredService <IOptions <StaticFileOptions> >().Value;
                options     = new StaticFileOptions
                {
                    RequestPath  = String.Empty,
                    FileProvider = fileProvider,
                    RedirectToAppendTrailingSlash = options.RedirectToAppendTrailingSlash,
                    ContentTypeProvider           = options.ContentTypeProvider,
                    DefaultContentType            = options.DefaultContentType,
                    ServeUnknownFileTypes         = options.ServeUnknownFileTypes,
                    HttpsCompression = options.HttpsCompression,

                    OnPrepareResponse = ctx =>
                    {
                        ctx.Context.Response.Headers[HeaderNames.CacheControl] = cacheControl;
                    },
                };

                app.UseStaticFiles(options);
            });
        }