2017-07-11 64 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

正確。我通常對文件名做一個正則表達式作爲回調的一部分。 –