コード例 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="context"></param>
        /// <param name="next"></param>
        /// <returns></returns>
        public async Task InvokeAsync(HttpContext context, RequestDelegate next)
        {
            var options = this.options.Value;

            if (options.RequestConstrainAsync is not null)
            {
                if (!await options.RequestConstrainAsync.Invoke(context))
                {
                    return;
                }
            }

            var request = context.Request;

            var model = new ImageResizeModel {
                ImagePath = request.Path
            };
            var imagePath = model.Resize(options)?.Replace(Path.DirectorySeparatorChar, '/');

            if (imagePath.IsNotNullOrEmpty())
            {
                context.Response.Redirect($"/{imagePath}");
            }

            await Task.CompletedTask;
        }
コード例 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="context"></param>
        public async Task InvokeAsync(HttpContext context)
        {
            await Task.FromResult(0);

            var options = this.options.Value;

            if (options.RequestConstrainAsync is not null)
            {
                if (!await options.RequestConstrainAsync.Invoke(context))
                {
                    return;
                }
            }

            var model = new ImageResizeModel {
                ImagePath = context.Request.Path
            };
            var imagePath = model.Resize(options)?.Replace(Path.DirectorySeparatorChar, '/');

            if (imagePath.IsNotNullOrEmpty())
            {
                context.Response.Redirect(imagePath);
            }
        }