Writing secure code. : PermissionSet : Security C# Source Code


Custom Search

C# Source Code » Security » PermissionSet »

 

Writing secure code.








    
 


using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Security;
using System.IO;
using System.Security.Permissions;

public class MainClass {
    public static void Main(){
        PermissionSet ps = new PermissionSet(System.Security.Permissions.PermissionState.None);

        ps.AddPermission(new FileIOPermission(FileIOPermissionAccess.Read |FileIOPermissionAccess.Write | FileIOPermissionAccess.Append,"c:\\temp\\temp.txt"));

        ps.Deny();
        //ps.Assert();

        FileStream fs = new FileStream(@"c:\temp\temp.txt",FileMode.OpenOrCreate, FileAccess.Write);
        StreamWriter m_streamWriter = new StreamWriter(fs);

        m_streamWriter.BaseStream.Seek(0, SeekOrigin.End);
        m_streamWriter.Write("Test");
    }
}

 
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Security
» PermissionSet