[英]NamedPipeServerStream Unauthorized Access exception
我從我的一位用戶那里收到了一個 Event Viever 條目,說發生了未經授權的訪問異常。 該過程從作為 SYSTEM 的服務啟動。 我能夠將錯誤縮小到創建 NamedPipeServerStream 的部分:
// <error in this block>
PipeSecurity pipeSa = new PipeSecurity();
pipeSa.AddAccessRule(new PipeAccessRule(new SecurityIdentifier(WellKnownSidType.WorldSid, null), PipeAccessRights.ReadWrite, AccessControlType.Allow));
NamedPipeServerStream np = new NamedPipeServerStream("streamname", PipeDirection.InOut,1,PipeTransmissionMode.Message,PipeOptions.None,16383,1, pipeSa);
// </error in this block>
while (true){
try{
if (!np.IsConnected)
np.WaitForConnection();
}catch(Exception e){
}
}
我很確定錯誤在上面的 3 行塊中。 它不會發生在我的任何計算機上,所以我不能重復錯誤。 上述代碼中的哪些內容不被視為最佳實踐並且可能導致錯誤?
錯誤信息圖片:
你問的問題細節很少。 因此,很難確定真正的原因是什么。 不過我願意試一試。
如果您查看未授權訪問異常的文檔
當操作系統由於 I/O 錯誤或特定類型的安全錯誤而拒絕訪問時引發的異常。
我們可以看到您的代碼已經吞噬了所有異常。 所以我們可以假設這是在創建 pipe 時拋出的。
我最好的猜測是,有時您無法訪問 pipe,因為系統無法正確訪問 pipe。 在做了一些快速研究之后。 這個問題似乎有很多值得一試的好信息。 轉述幾個答案:
有兩件事會導致在同一 pipe 上實例化第二個或后續 NamedPipeServerStream 失敗:
您可能缺少需要添加訪問權限的權限,也許您需要為系統提供控制:
pipeSa.AddAccessRule(new PipeAccessRule("SYSTEM", PipeAccessRights.FullControl, AccessControlType.Allow));
pipeSa.AddAccessRule(pa);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.