2010-08-17 7 views
9

मैं नीचे इस कोड से डुप्लीकेट FileSystemAccessRule हो रही है:डुप्लिकेट GetAccessRules, FileSystemAccessRule प्रविष्टियां

C:\inetpub\wwwroot\AspInfo\Account 
BUILTIN\IIS_IUSRS : Allow : ReadAndExecute, Synchronize 
BUILTIN\IIS_IUSRS : Allow : -1610612736 
NT SERVICE\TrustedInstaller : Allow : FullControl 
NT SERVICE\TrustedInstaller : Allow : 268435456 

और मैं बाहर क्या या कारण है कि यह है काम नहीं कर सकता।

और दिखाए जा रहे अनुमतियों से मेल नहीं खाता है जो मैं फ़ाइल फ़ाइल प्रबंधक देख सकता हूं। उदाहरण के लिए, मैं इस या समान पुनरावृत्ति से "सूची फ़ोल्डर सामग्री" अनुमति कैसे प्राप्त करूं? यदि कोई .NET दस्तावेज़ों के भीतर किसी उदाहरण के बारे में जानता है तो यह सहायक होगा।

protected void directoryInfo() 
{ 
    var di = new DirectoryInfo(Server.MapPath("/")); 
    foreach (DirectoryInfo dir in di.GetDirectories()) 
    { 
    Response.Write(dir.FullName + "<br/>"); 
    DirectorySecurity ds = dir.GetAccessControl(); 
    foreach (FileSystemAccessRule fsar in ds.GetAccessRules(true, true, typeof(System.Security.Principal.NTAccount))) 
    { 
     string userName = fsar.IdentityReference.Value; 
     string userRights = fsar.FileSystemRights.ToString(); 
     string userAccessType = fsar.AccessControlType.ToString(); 
     Response.Write(userName + " : " + userAccessType + " : " + userRights + "<br/>"); 
    } 
    } 
} 

उत्तर

13

आप विरासत में मिला नियमों के लिए और नियमों कि स्पष्ट रूप से उस फ़ोल्डर पर सेट कर रहे हैं के लिए अलग नियम प्रविष्टियों मिल जाएगा। प्रत्येक नियम पर प्रचार सेटिंग्स के आधार पर भी एक अंतर है। उदाहरण के लिए, आपके पास उप-फ़ोल्डर्स को प्रसारित करने के लिए सेट की गई अनुमतियों का एक सेट हो सकता है, और फ़ोल्डर के भीतर फ़ाइलों के लिए एक अलग सेट हो सकता है। आपका कोड उस फ़ोल्डर पर ऑडिट नियम (एसएसीएल) भी प्राप्त कर रहा है जहां आप केवल एक्सेस अनुमतियां (डीएसीएल) चाहते हैं।

इस प्रयास करें:

protected void directoryInfo() 
{ 
    var di = new DirectoryInfo(Server.MapPath("/")); 
    foreach (DirectoryInfo dir in di.GetDirectories()) 
    { 
    Response.Write(dir.FullName + "<br/>"); 
    DirectorySecurity ds = dir.GetAccessControl(AccessControlSections.Access); 
    foreach (FileSystemAccessRule fsar in ds.GetAccessRules(true, true, typeof(System.Security.Principal.NTAccount))) 
    { 
     string userName = fsar.IdentityReference.Value; 
     string userRights = fsar.FileSystemRights.ToString(); 
     string userAccessType = fsar.AccessControlType.ToString(); 
     string ruleSource = fsar.IsInherited ? "Inherited" : "Explicit"; 
     string rulePropagation = fsar.PropagationFlags.ToString(); 
     string ruleInheritance = fsar.InheritanceFlags.ToString(); 
     Response.Write(userName + " : " + userAccessType + " : " + userRights + " : " + ruleSource + " : " + rulePropagation + " : " + ruleInheritance + "<br/>"); 
    } 
    } 
} 

ReadAndExecute अनुमति आप देख रहे हैं "सूची फ़ोल्डर सामग्री" अनुमति भी शामिल है। आप FileSystemRights enum में उचित ध्वज का उपयोग कर व्यक्तिगत अनुमतियों की जांच कर सकते हैं। उदाहरण के लिए:

if (fsar.FileSystemRights && FileSystemRights.ListDirectory) 
    Console.WriteLine("Has List Directory permission"); 
+0

'फ़ाइल सिस्टम सिस्टम' का उपयोग करने वाले 'if' मूल्यांकन की अनुमति नहीं है। – Thomas

+0

बस 'if (FileSystemRights.ListDirectory) {...} 'की जांच करने में सक्षम होना चाहिए। https://msdn.microsoft.com/en-us/library/system.security.accesscontrol.filesystemrights(v=vs.110).aspx आपको यह देखने की ज़रूरत नहीं है कि आपके पास किसी दिए गए निर्देशिका पर 'FileSystemRights' है या नहीं - अगर आप लूप में हैं, आपके पास निर्देशिकाएं हैं। यदि आपके पास निर्देशिकाएं हैं, तो आपके पास 'FileSystemAccessRule' गुण हैं। यदि आप 'FileSystemAccessRule' गुणों के लूप में हैं, तो आपके पास' FileSystemRights' गुण होंगे, गारंटीकृत। – vapcguy

+0

@vapcguy यह फ़ाइलसिस्टमऑडिट नियम आइटम को कैसे बाहर करता है? – Chalky