2 // System.Net.WebPermissionAttribute.cs
5 // Andreas Nahr (ClassDevelopment@A-SoftTech.com)
7 // (C) 2003 Andreas Nahr
11 using System.Security;
12 using System.Security.Permissions;using System.Text.RegularExpressions;
16 [AttributeUsage (AttributeTargets.Assembly | AttributeTargets.Class
17 | AttributeTargets.Struct | AttributeTargets.Constructor
18 | AttributeTargets.Method, AllowMultiple = true, Inherited = false)]
20 public sealed class WebPermissionAttribute : CodeAccessSecurityAttribute
27 public WebPermissionAttribute (SecurityAction action) : base (action)
33 public string Accept {
34 get { return m_accept.ToString (); }
37 throw new ArgumentException ("The parameter 'Accept' can be set only once.");
39 throw new ArgumentException ("The parameter 'Accept' cannot be null.");
44 public string AcceptPattern {
45 get { return m_accept.ToString (); }
48 throw new ArgumentException ("The parameter 'Accept' can be set only once.");
50 throw new ArgumentException ("The parameter 'Accept' cannot be null.");
51 m_accept = new Regex (value, RegexOptions.IgnoreCase);
55 public string Connect {
56 get { return m_connect.ToString (); }
58 if (m_connect != null)
59 throw new ArgumentException ("The parameter 'Connect' can be set only once.");
61 throw new ArgumentException ("The parameter 'Connect' cannot be null.");
65 public string ConnectPattern {
66 get { return m_connect.ToString (); }
68 if (m_connect != null)
69 throw new ArgumentException ("The parameter 'Connect' can be set only once.");
71 throw new ArgumentException ("The parameter 'Connect' cannot be null.");
72 m_connect = new Regex (value, RegexOptions.IgnoreCase);
78 public override IPermission CreatePermission ()
80 if (this.Unrestricted)
81 return new WebPermission (PermissionState.Unrestricted);
82 WebPermission newPermission = new WebPermission ();
85 if (m_accept is Regex)
86 newPermission.AddPermission (NetworkAccess.Accept, (Regex)m_accept);
88 newPermission.AddPermission (NetworkAccess.Accept, (string)m_accept);
90 if (m_connect != null)
92 if (m_connect is Regex)
93 newPermission.AddPermission (NetworkAccess.Connect, (Regex)m_connect);
95 newPermission.AddPermission (NetworkAccess.Connect, (string)m_connect);