/// <summary>
        /// Adds middleware for adding the X-Frame-Options header.
        /// </summary>
        /// <param name="app">The <see cref="IApplicationBuilder"/> instance this method extends.</param>
        /// <param name="optionsAction">A delegate used for setting up the <see cref="FrameOptionsOptions"/>.</param>
        public static IApplicationBuilder UseFrameOptions(this IApplicationBuilder app, Action <FrameOptionsOptionsBuilder> optionsAction)
        {
            FrameOptionsOptionsBuilder optionsBuilder = new FrameOptionsOptionsBuilder();

            optionsAction(optionsBuilder);
            FrameOptionsOptions options = optionsBuilder.Build();

            return(app.UseMiddleware <FrameOptionsMiddleware>(options));
        }
Ejemplo n.º 2
0
        public FrameOptionsMiddleware(RequestDelegate next, FrameOptionsOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            this.next = next;

            switch (options.Option)
            {
            case FrameOption.Deny:
                headerValue = "deny";
                break;

            case FrameOption.SameOrigin:
                headerValue = "sameorigin";
                break;

            case FrameOption.AllowFromDomain:
                headerValue = $"allow-from: {options.AllowedDomain}";
                break;
            }
        }
Ejemplo n.º 3
0
 internal FrameOptionsOptionsBuilder()
 {
     options = new FrameOptionsOptions();
 }