流浪のwolf

卷帝

导航

netCore 配置跨域 封装成文件

namespace Zhaoxi.Manage.MentApi.Utility.RegisterExt
{
    /// <summary>
    /// 跨域扩展
    /// </summary>
    public static class CrosServiceExtension
    {
        /// <summary>
        /// 配置支持跨域的策略
        /// </summary>
        /// <param name="builder"></param>
        public static void CrosDomainsPolicy(this WebApplicationBuilder builder)
        {
            builder.Services.AddCors(option =>
            {
                //所有的Api都支持跨域
                option.AddPolicy("AllCrosDomainsPolicy", corsbuilder =>
                {
                    corsbuilder.AllowAnyOrigin()
                    .AllowAnyHeader()
                    .AllowAnyMethod();
                });
            });
        }

        /// <summary>
        /// 配置生效
        /// </summary>
        /// <param name="app"></param>
        public static void UseCrosDomainsPolicy(this WebApplication app) => app.UseCors("AllCrosDomainsPolicy");




    }
}

 

posted on 2024-01-06 14:43  流浪のwolf  阅读(9)  评论(0编辑  收藏  举报