Skip to content

Enable CORS For Serenity Applications

Victor Tomaili edited this page May 3, 2021 · 1 revision
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddAntiforgery(options => options.HeaderName = "X-CSRF-TOKEN");
            //add following code for enabling cors to the project
            services.AddCors(options =>
            {
                options.AddPolicy("AllowAllOrigin",
                    builder => builder.AllowAnyOrigin());
            });
            // code ends here
            services.AddMvc(options =>
            {
                //options.Filters.Add(new AutoValidateAntiforgeryTokenAttribute());
                };
            });
            // ...
            // ...

        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            // ...
            // ...
            app.UseDynamicScripts();
            // use CORS here
            app.UseCors("AllowAllOrigin");
            app.UseMvc(routes =>`
            {
            });
            // ....
Clone this wiki locally