Refusing permissions : File Permission « File Directory Stream « C# / CSharp Tutorial

Home
C# / CSharp Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statement
5.String
6.struct
7.Class
8.Operator Overload
9.delegate
10.Attribute
11.Data Structure
12.Assembly
13.Date Time
14.Development
15.File Directory Stream
16.Preprocessing Directives
17.Regular Expression
18.Generic
19.Reflection
20.Thread
21.I18N Internationalization
22.LINQ
23.GUI Windows Forms
24.Windows Presentation Foundation
25.Windows Communication Foundation
26.Workflow
27.2D
28.Design Patterns
29.Windows
30.XML
31.XML LINQ
32.ADO.Net
33.Network
34.Directory Services
35.Security
36.unsafe
C# / C Sharp
C# / C Sharp by API
C# / CSharp Open Source
C# / CSharp Tutorial » File Directory Stream » File Permission 
15.12.4.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
15.12.File Permission
15.12.1.Requesting minimum permissions
15.12.2.Requesting optional permissions
15.12.3.Requesting a permission set
15.12.4.Refusing permissions
15.12.5.Demanding permissions
15.12.6.Permission sets
15.12.7.Declarative Permission demo
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.