C# 支持跨域请求

            #region 支持跨域请求
            context.Response.ClearHeaders();
            string origin = context.Request.Headers["Origin"];
            context.Response.AppendHeader("Access-Control-Allow-Origin",
                string.IsNullOrEmpty(origin) ? "*" : origin);
            string requestHeaders = context.Request.Headers["Access-Control-Request-Headers"];
            context.Response.AppendHeader("Access-Control-Allow-Headers",
                string.IsNullOrEmpty(requestHeaders) ? "*" : requestHeaders);
            context.Response.AppendHeader("Access-Control-Allow-Methods", "POST, OPTIONS");
            #endregion

比如在登录页面允许跨域请求


C# 支持跨域请求_第1张图片
Paste_Image.png

你可能感兴趣的:(C# 支持跨域请求)