asp.net - B2C 和 Azure 应用服务的 CORS 问题

标签 asp.net cors azure-ad-b2c

我通过在 Controller 中使用 AddCors 和 EnableCors 在我的 ASP.NET/Angular 应用程序中启用了 CORS。我的应用程序正在与 AD B2C 页面进行通信。构建后,我在控制台中出现此错误:

Access to XMLHttpRequest at 'https://XXX.b2clogin.com/ (redirected from 'https://XXX.azurewebsites.net/User/Info') from origin 'https://XXX.azurewebsites.net' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.



启动.cs:
            services.AddCors(options =>
        {
            options.AddPolicy("CorsPolicy",
                builder => builder.AllowAnyOrigin()
                .AllowAnyMethod()
                .AllowAnyHeader()
                .AllowCredentials());
        });

Controller :
[EnableCors("CorsPolicy")]
[Authorize]
public class UserEditController : Controller

我也在 Azure 上启用了 CORS,方法如下:Allowed Origins - * .

更新:
[Route("User/Info")]
[HttpGet]
public async Task<IActionResult> LoggedInUserInfo()
{
    if (User.Identity.IsAuthenticated)
    {
        var user = ((ClaimsIdentity)User.Identity).FindFirst(ClaimTypes.NameIdentifier).Value;
        var viewmodel = await userService.GetUserByObjectId(user);
        return Json(new { loggedIn = "true", user = viewmodel });
    }
    return Json(new { loggedIn = "false" });
}

最佳答案

您似乎正在尝试来自 的跨域请求。 https://xxx.azurewebsites.net/ 域到 https://xxx.b2clogin.com/ 领域。

目前.b2clogin.com域不允许来自任何其他域的任何跨域请求。

关于asp.net - B2C 和 Azure 应用服务的 CORS 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54562349/

相关文章:

Azure AD B2C : mixing built-in flows with custom policies and sharing encryption keys for JWTs

c# - 无法还原 ASP.NET Core 1.0 RTM 解决方案

c# - 将 Xml 转换为数据表

c# - 使用数组中的索引作为数据值?

.net - 匹配不包含某个字符序列的字符串

javascript - Web API 2.0 上的 COR 请求

ajax - 支持 CORS 的服务器?

php - Azure B2C 与 PHP 集成

javascript - Safari xhr (AJAX) 请求 w/跨域重定向失败

Azure AD B2C 在回复 url 中添加参数