【问题标题】:OneDrive Search throws UnknownError when search contains "*"当搜索包含“*”时,OneDrive 搜索会引发 UnknownError
【发布时间】:2017-07-11 20:45:51
【问题描述】:

This is a copy paste from my original posted github issue

我正在开发一个利用 Microsoft.Graph SDK 的原型应用程序。我注意到,如果我在“实时”/个人 OneDrive 帐户上运行以下代码,它就可以正常工作并返回我期望的文件。但是,如果我对我的 OneDrive for Business 运行相同的代码,它会在 Microsoft.Graph.Core 中引发内部异常。我怀疑原因是我的搜索 URL 包含错误中提到的 *,但为什么它在搜索真实帐户时有效,而在搜索工作帐户时中断?

示例代码片段:

var graphserviceClient = new GraphServiceClient(
         new DelegateAuthenticationProvider(
             (requestMessage) =>
             {
                 requestMessage.Headers.Authorization = new AuthenticationHeaderValue("bearer", ADALAuth.CurrentAccessToken);

                 return Task.FromResult(0);
             }));

            var drive = graphserviceClient.Me.Drive.Request().GetAsync().Result;
            var collection = graphserviceClient.Me.Drive.Search("*.xyz").Request().GetAsync().GetAwaiter().GetResult();

返回的错误信息是:

Code: UnknownError
Message: A potentially dangerous Request.Path value was detected from the client (*).

Inner error

堆栈跟踪:

   at Microsoft.Graph.HttpProvider.<SendAsync>d__19.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Graph.BaseRequest.<SendRequestAsync>d__36.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Graph.BaseRequest.<SendAsync>d__32`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Graph.DriveSearchRequest.<GetAsync>d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at _Default.Page_Load(Object sender, EventArgs e) in e:\Profile\Documents\Visual Studio 2015\WebSites\AzureWebApp\Default.aspx.cs:line 33
   at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
   at System.Web.UI.Control.OnLoad(EventArgs e)
   at System.Web.UI.Control.LoadRecursive()
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

【问题讨论】:

    标签: microsoft-graph-api onedrive


    【解决方案1】:

    在幕后,Graph 会根据您的帐户类型将您的请求路由到两个不同的系统。因此,这两个系统之间存在一些细微的差异。

    无论如何,您不应该需要*,因为搜索已经在搜索您在其他字符串中传递的字符串。换句话说,*.xyz.xyz 都被翻译成 *.xyz*。它将以这种方式在包括文件名、元数据和文件内容在内的多个字段中匹配此查询。

    【讨论】:

    • 因此,如果我想根据文件扩展名搜索并仅返回特定的 OneDrive 文件,我将不得不搜索 .xyz,然后根据文件名结尾过滤响应?
    • 正确。作为回调的一部分,我通常对文件名执行正则表达式。
    猜你喜欢
    • 2021-08-06
    • 2021-03-11
    • 1970-01-01
    • 1970-01-01
    • 2016-04-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-10
    • 1970-01-01
    相关资源
    最近更新 更多