DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   C# (http://www.daniweb.com/forums/forum61.html)
-   -   Code Snippet: Using Code Access Security (CAS) to programatically refuse writing to a drive - Shalvin (http://www.daniweb.com/forums/thread217043.html)

Shalvin Feb 26th, 2008 6:05 am
Using Code Access Security (CAS) to programatically refuse writing to a drive - Shalvin
 
CAS is the programatically means by which you secure the resouce of a system like file system, printer, registry, etc. in contrast to Role Base Security (RBS)

  1. using System.Security.Permissions;
  2. using System.Security;
  3. using System.IO;
  4.  
  5. [assembly: FileIOPermissionAttribute(SecurityAction.RequestRefuse , Write="d:\\")]
  6. namespace WindowsFormsApplication1
  7. {
  8. public partial class Form1 : Form
  9. {
  10. StreamWriter sw;
  11. private void button1_Click(object sender, EventArgs e)
  12. {
  13. sw = File.CreateText("d:\\Shalvin.txt");
  14. sw.WriteLine("Hello");
  15. sw.Close();
  16. }

All times are GMT -4. The time now is 2:09 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC