Mega Code Archive

 
Categories / C# Tutorial / File Directory Stream
 

Refusing permissions

using System; using System.IO; using System.Security.Permissions; [assembly:FileIOPermissionAttribute(SecurityAction.RequestRefuse,Unrestricted=true)] class MainClass {   public static void Main()    {     FileStream fsOut = File.Create(@"c:\\temp\\test.txt");     StreamWriter sw = new StreamWriter(fsOut);     sw.WriteLine("str");     sw.Flush();     sw.Close();   } } Unhandled Exception: System.Security.SecurityException: Request for the permission of type 'System.S ecurity.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77 a5c561934e089' failed. at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boole an isPermSet) at System.Security.CodeAccessPermission.Demand() at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, St ring msgPath, Boolean bFromProxy) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int 32 bufferSize, FileOptions options) at MainClass.Main() The action that failed was: Demand The type of the first permission that failed was: System.Security.Permissions.FileIOPermission The first permission that failed was: The demand was for: The granted set of the failing assembly was: The refused set of the failing assembly was: The assembly or AppDomain that failed was: main, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null The method that caused the failure was: Void Main() The Zone of the assembly that failed was: MyComputer The Url of the assembly that failed was: file:///C:/Java_Dev/WEB/dev/CSharp/main.exe