2017-07-11 66 views
1

This is a copy paste from my original posted github issueOneDrive搜索抛出不明错误时搜索包含“*”

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

示例代码段:

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) 

回答

1

在幕后,图为路由你回覆根据您的账户类型寻求两种不同的系统。正因为如此,这两个系统之间有一些细微的差别。

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

+0

因此,如果我想仅基于文件扩展名搜索并返回特定的OneDrive文件,那么我将不得不搜索'.xyz',然后过滤基于文件名结尾的响应。 –

+0

正确。我通常对文件名做一个正则表达式作为回调的一部分。 –