You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Microsoft Graph 5.56中SignInsRequestBuilder无Filter方法报错求助

解决方案

Microsoft Graph SDK v5(含你使用的5.56版本)已废弃v4版本中的链式Filter/OrderBy扩展方法,需通过RequestConfiguration配置查询参数。

修正后的代码

var signIns = await graphClient
    .AuditLogs
    .SignIns
    .GetAsync(requestConfiguration =>
    {
        requestConfiguration.QueryParameters.Filter = $"UserPrincipalName eq '{UserPrincipalName}' and IsInteractive eq true and status/errorCode eq 0";
        requestConfiguration.QueryParameters.OrderBy = new[] { "CreatedDateTime" };
    });

额外建议

  • 避免注入风险:直接拼接字符串到Filter存在安全隐患,建议使用参数化查询:
var signIns = await graphClient
    .AuditLogs
    .SignIns
    .GetAsync(requestConfiguration =>
    {
        requestConfiguration.QueryParameters.Filter = $"UserPrincipalName eq @upn and IsInteractive eq true and status/errorCode eq 0";
        requestConfiguration.QueryParameters.AdditionalQueryParameters.Add("@upn", UserPrincipalName);
    });
  • 确认命名空间:确保代码文件顶部已引用using Microsoft.Graph;,RequestConfiguration相关扩展方法依赖此命名空间。

内容的提问来源于stack exchange,提问作者kudlatiger

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.19 06:59:50