Exemple #1
0
        /// <summary>
        /// Installs WordPress middleware.
        /// </summary>
        /// <param name="app">The application builder.</param>
        /// <param name="config">WordPress instance configuration.</param>
        /// <param name="path">Physical location of wordpress folder. Can be absolute or relative to the current directory.</param>
        public static IApplicationBuilder UseWordPress(this IApplicationBuilder app, WordPressConfig config, string path = "wordpress")
        {
            // wordpress root path:
            var root      = System.IO.Path.GetFullPath(path);
            var fprovider = new PhysicalFileProvider(root);

            // TODO: caching

            // url rewriting:
            app.UseRewriter(new RewriteOptions().Add(context => ShortUrlRule(context, fprovider)));

            // handling php files:
            app.UsePhp(new PhpRequestOptions()
            {
                ScriptAssembliesName = new[] { typeof(WpApp).Assembly.FullName },
                BeforeRequest        = config.Apply,
                RootPath             = root,
            });

            // static files
            app.UseStaticFiles(new StaticFileOptions()
            {
                FileProvider = fprovider
            });

            return(app);
        }
        /// <summary>
        /// Installs WordPress middleware.
        /// </summary>
        public static IApplicationBuilder UseWordPress(this IApplicationBuilder app, WordPressConfig config)
        {
            // TODO: caching

            // url rewriting:
            app.UseRewriter(new RewriteOptions().Add(ShortUrlRule));

            // handling php files:
            app.UsePhp(new PhpRequestOptions()
            {
                ScriptAssembliesName = new[] { typeof(WpApp).Assembly.FullName },
                BeforeRequest        = config.Apply,
            });

            // static files
            app.UseStaticFiles();

            return(app);
        }