C# 如何在ApicController中读取已登录的用户?

C# 如何在ApicController中读取已登录的用户?,c#,model-view-controller,cross-domain-policy,C#,Model View Controller,Cross Domain Policy,在WebAPI mvc项目中,如何读取ApicController中的登录用户 通过添加WithCredentials:true,将凭据与请求一起从客户端发送 $.ajax({url:ajaxURL, 跨域:正确, xhrFields:{ 证书:正确 }, 成功:函数(数据){警报(数据);}, }); 从WebAPI服务器添加以下装饰,以允许跨来源请求并允许证书: [EnableCors(来源:”,标题:“*”, 方法:“*”,SupportsCredentials=true)] Suppor

在WebAPI mvc项目中,如何读取ApicController中的登录用户

  • 通过添加WithCredentials:true,将凭据与请求一起从客户端发送

    $.ajax({url:ajaxURL,
    跨域:正确, xhrFields:{ 证书:正确 }, 成功:函数(数据){警报(数据);}, });

  • 从WebAPI服务器添加以下装饰,以允许跨来源请求并允许证书: [EnableCors(来源:”,标题:“*”, 方法:“*”,SupportsCredentials=true)]

  • SupportsCredentials将在响应中添加标头访问控制允许凭据=true

  • 现在您可以使用User.Identity.Name