Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / ndp / fx / src / CompMod / System / Security / Permissions / AspNetHostingPermission.cs / 1 / AspNetHostingPermission.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.Web {
using System.Security;
using System.Security.Permissions;
using System.Globalization;
//NOTE: While AspNetHostingPermissionAttribute resides in System.DLL,
// no classes from that DLL are able to make declarative usage of AspNetHostingPermission.
[Serializable]
public enum AspNetHostingPermissionLevel
{
None = 100,
Minimal = 200,
Low = 300,
Medium = 400,
High = 500,
Unrestricted = 600
}
[AttributeUsage(AttributeTargets.All, AllowMultiple=true, Inherited=false )]
[Serializable]
sealed public class AspNetHostingPermissionAttribute : CodeAccessSecurityAttribute
{
AspNetHostingPermissionLevel _level;
public AspNetHostingPermissionAttribute ( SecurityAction action ) : base( action ) {
_level = AspNetHostingPermissionLevel.None;
}
public AspNetHostingPermissionLevel Level {
get {
return _level;
}
set {
AspNetHostingPermission.VerifyAspNetHostingPermissionLevel(value, "Level");
_level = value;
}
}
public override IPermission CreatePermission() {
if (Unrestricted) {
return new AspNetHostingPermission(PermissionState.Unrestricted);
}
else {
return new AspNetHostingPermission(_level);
}
}
}
///
///
///
///
[Serializable]
public sealed class AspNetHostingPermission : CodeAccessPermission, IUnrestrictedPermission {
AspNetHostingPermissionLevel _level;
static internal void VerifyAspNetHostingPermissionLevel(AspNetHostingPermissionLevel level, string arg) {
switch (level) {
case AspNetHostingPermissionLevel.Unrestricted:
case AspNetHostingPermissionLevel.High:
case AspNetHostingPermissionLevel.Medium:
case AspNetHostingPermissionLevel.Low:
case AspNetHostingPermissionLevel.Minimal:
case AspNetHostingPermissionLevel.None:
break;
default:
throw new ArgumentException(arg);
}
}
///
///
/// Creates a new instance of the System.Net.AspNetHostingPermission
/// class that passes all demands or that fails all demands.
///
///
public AspNetHostingPermission(PermissionState state) {
switch (state) {
case PermissionState.Unrestricted:
_level = AspNetHostingPermissionLevel.Unrestricted;
break;
case PermissionState.None:
_level = AspNetHostingPermissionLevel.None;
break;
default:
throw new ArgumentException(SR.GetString(SR.InvalidArgument, state.ToString(), "state"));
}
}
public AspNetHostingPermission(AspNetHostingPermissionLevel level) {
VerifyAspNetHostingPermissionLevel(level, "level");
_level = level;
}
public AspNetHostingPermissionLevel Level {
get {
return _level;
}
set {
VerifyAspNetHostingPermissionLevel(value, "Level");
_level = value;
}
}
// IUnrestrictedPermission interface methods
///
///
/// Checks the overall permission state of the object.
///
///
public bool IsUnrestricted() {
return _level == AspNetHostingPermissionLevel.Unrestricted;
}
// IPermission interface methods
///
///
/// Creates a copy of a System.Net.AspNetHostingPermission
///
///
public override IPermission Copy () {
return new AspNetHostingPermission(_level);
}
///
/// Returns the logical union between two System.Net.AspNetHostingPermission instances.
///
public override IPermission Union(IPermission target) {
if (target == null) {
return Copy();
}
if (target.GetType() != typeof(AspNetHostingPermission)) {
throw new ArgumentException(SR.GetString(SR.InvalidArgument, target == null ? "null" : target.ToString(), "target"));
}
AspNetHostingPermission other = (AspNetHostingPermission) target;
if (Level >= other.Level) {
return new AspNetHostingPermission(Level);
}
else {
return new AspNetHostingPermission(other.Level);
}
}
///
/// Returns the logical intersection between two System.Net.AspNetHostingPermission instances.
///
public override IPermission Intersect(IPermission target) {
if (target == null) {
return null;
}
if (target.GetType() != typeof(AspNetHostingPermission)) {
throw new ArgumentException(SR.GetString(SR.InvalidArgument, target == null ? "null" : target.ToString(), "target"));
}
AspNetHostingPermission other = (AspNetHostingPermission) target;
if (Level <= other.Level) {
return new AspNetHostingPermission(Level);
}
else {
return new AspNetHostingPermission(other.Level);
}
}
///
/// Compares two System.Net.AspNetHostingPermission instances.
///
public override bool IsSubsetOf(IPermission target) {
if (target == null) {
return _level == AspNetHostingPermissionLevel.None;
}
if (target.GetType() != typeof(AspNetHostingPermission)) {
throw new ArgumentException(SR.GetString(SR.InvalidArgument, target == null ? "null" : target.ToString(), "target"));
}
AspNetHostingPermission other = (AspNetHostingPermission) target;
return Level <= other.Level;
}
///
///
public override void FromXml(SecurityElement securityElement) {
if (securityElement == null) {
throw new ArgumentNullException(SR.GetString(SR.AspNetHostingPermissionBadXml,"securityElement"));
}
if (!securityElement.Tag.Equals("IPermission")) {
throw new ArgumentException(SR.GetString(SR.AspNetHostingPermissionBadXml,"securityElement"));
}
string className = securityElement.Attribute("class");
if (className == null) {
throw new ArgumentException(SR.GetString(SR.AspNetHostingPermissionBadXml,"securityElement"));
}
if (className.IndexOf(this.GetType().FullName, StringComparison.Ordinal) < 0) {
throw new ArgumentException(SR.GetString(SR.AspNetHostingPermissionBadXml,"securityElement"));
}
string version = securityElement.Attribute("version");
if (string.Compare(version, "1", StringComparison.OrdinalIgnoreCase) != 0) {
throw new ArgumentException(SR.GetString(SR.AspNetHostingPermissionBadXml,"version"));
}
string level = securityElement.Attribute("Level");
if (level == null) {
_level = AspNetHostingPermissionLevel.None;
}
else {
_level = (AspNetHostingPermissionLevel) Enum.Parse(typeof(AspNetHostingPermissionLevel), level);
}
}
///
/// [To be supplied.]
///
public override SecurityElement ToXml() {
SecurityElement securityElement = new SecurityElement("IPermission");
securityElement.AddAttribute("class", this.GetType().FullName + ", " + this.GetType().Module.Assembly.FullName.Replace( '\"', '\'' ));
securityElement.AddAttribute("version", "1" );
securityElement.AddAttribute("Level", Enum.GetName(typeof(AspNetHostingPermissionLevel), _level));
if (IsUnrestricted()) {
securityElement.AddAttribute("Unrestricted", "true");
}
return securityElement;
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.Web {
using System.Security;
using System.Security.Permissions;
using System.Globalization;
//NOTE: While AspNetHostingPermissionAttribute resides in System.DLL,
// no classes from that DLL are able to make declarative usage of AspNetHostingPermission.
[Serializable]
public enum AspNetHostingPermissionLevel
{
None = 100,
Minimal = 200,
Low = 300,
Medium = 400,
High = 500,
Unrestricted = 600
}
[AttributeUsage(AttributeTargets.All, AllowMultiple=true, Inherited=false )]
[Serializable]
sealed public class AspNetHostingPermissionAttribute : CodeAccessSecurityAttribute
{
AspNetHostingPermissionLevel _level;
public AspNetHostingPermissionAttribute ( SecurityAction action ) : base( action ) {
_level = AspNetHostingPermissionLevel.None;
}
public AspNetHostingPermissionLevel Level {
get {
return _level;
}
set {
AspNetHostingPermission.VerifyAspNetHostingPermissionLevel(value, "Level");
_level = value;
}
}
public override IPermission CreatePermission() {
if (Unrestricted) {
return new AspNetHostingPermission(PermissionState.Unrestricted);
}
else {
return new AspNetHostingPermission(_level);
}
}
}
///
///
///
///
[Serializable]
public sealed class AspNetHostingPermission : CodeAccessPermission, IUnrestrictedPermission {
AspNetHostingPermissionLevel _level;
static internal void VerifyAspNetHostingPermissionLevel(AspNetHostingPermissionLevel level, string arg) {
switch (level) {
case AspNetHostingPermissionLevel.Unrestricted:
case AspNetHostingPermissionLevel.High:
case AspNetHostingPermissionLevel.Medium:
case AspNetHostingPermissionLevel.Low:
case AspNetHostingPermissionLevel.Minimal:
case AspNetHostingPermissionLevel.None:
break;
default:
throw new ArgumentException(arg);
}
}
///
///
/// Creates a new instance of the System.Net.AspNetHostingPermission
/// class that passes all demands or that fails all demands.
///
///
public AspNetHostingPermission(PermissionState state) {
switch (state) {
case PermissionState.Unrestricted:
_level = AspNetHostingPermissionLevel.Unrestricted;
break;
case PermissionState.None:
_level = AspNetHostingPermissionLevel.None;
break;
default:
throw new ArgumentException(SR.GetString(SR.InvalidArgument, state.ToString(), "state"));
}
}
public AspNetHostingPermission(AspNetHostingPermissionLevel level) {
VerifyAspNetHostingPermissionLevel(level, "level");
_level = level;
}
public AspNetHostingPermissionLevel Level {
get {
return _level;
}
set {
VerifyAspNetHostingPermissionLevel(value, "Level");
_level = value;
}
}
// IUnrestrictedPermission interface methods
///
///
/// Checks the overall permission state of the object.
///
///
public bool IsUnrestricted() {
return _level == AspNetHostingPermissionLevel.Unrestricted;
}
// IPermission interface methods
///
///
/// Creates a copy of a System.Net.AspNetHostingPermission
///
///
public override IPermission Copy () {
return new AspNetHostingPermission(_level);
}
///
/// Returns the logical union between two System.Net.AspNetHostingPermission instances.
///
public override IPermission Union(IPermission target) {
if (target == null) {
return Copy();
}
if (target.GetType() != typeof(AspNetHostingPermission)) {
throw new ArgumentException(SR.GetString(SR.InvalidArgument, target == null ? "null" : target.ToString(), "target"));
}
AspNetHostingPermission other = (AspNetHostingPermission) target;
if (Level >= other.Level) {
return new AspNetHostingPermission(Level);
}
else {
return new AspNetHostingPermission(other.Level);
}
}
///
/// Returns the logical intersection between two System.Net.AspNetHostingPermission instances.
///
public override IPermission Intersect(IPermission target) {
if (target == null) {
return null;
}
if (target.GetType() != typeof(AspNetHostingPermission)) {
throw new ArgumentException(SR.GetString(SR.InvalidArgument, target == null ? "null" : target.ToString(), "target"));
}
AspNetHostingPermission other = (AspNetHostingPermission) target;
if (Level <= other.Level) {
return new AspNetHostingPermission(Level);
}
else {
return new AspNetHostingPermission(other.Level);
}
}
///
/// Compares two System.Net.AspNetHostingPermission instances.
///
public override bool IsSubsetOf(IPermission target) {
if (target == null) {
return _level == AspNetHostingPermissionLevel.None;
}
if (target.GetType() != typeof(AspNetHostingPermission)) {
throw new ArgumentException(SR.GetString(SR.InvalidArgument, target == null ? "null" : target.ToString(), "target"));
}
AspNetHostingPermission other = (AspNetHostingPermission) target;
return Level <= other.Level;
}
///
///
public override void FromXml(SecurityElement securityElement) {
if (securityElement == null) {
throw new ArgumentNullException(SR.GetString(SR.AspNetHostingPermissionBadXml,"securityElement"));
}
if (!securityElement.Tag.Equals("IPermission")) {
throw new ArgumentException(SR.GetString(SR.AspNetHostingPermissionBadXml,"securityElement"));
}
string className = securityElement.Attribute("class");
if (className == null) {
throw new ArgumentException(SR.GetString(SR.AspNetHostingPermissionBadXml,"securityElement"));
}
if (className.IndexOf(this.GetType().FullName, StringComparison.Ordinal) < 0) {
throw new ArgumentException(SR.GetString(SR.AspNetHostingPermissionBadXml,"securityElement"));
}
string version = securityElement.Attribute("version");
if (string.Compare(version, "1", StringComparison.OrdinalIgnoreCase) != 0) {
throw new ArgumentException(SR.GetString(SR.AspNetHostingPermissionBadXml,"version"));
}
string level = securityElement.Attribute("Level");
if (level == null) {
_level = AspNetHostingPermissionLevel.None;
}
else {
_level = (AspNetHostingPermissionLevel) Enum.Parse(typeof(AspNetHostingPermissionLevel), level);
}
}
///
/// [To be supplied.]
///
public override SecurityElement ToXml() {
SecurityElement securityElement = new SecurityElement("IPermission");
securityElement.AddAttribute("class", this.GetType().FullName + ", " + this.GetType().Module.Assembly.FullName.Replace( '\"', '\'' ));
securityElement.AddAttribute("version", "1" );
securityElement.AddAttribute("Level", Enum.GetName(typeof(AspNetHostingPermissionLevel), _level));
if (IsUnrestricted()) {
securityElement.AddAttribute("Unrestricted", "true");
}
return securityElement;
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ZoneLinkButton.cs
- OrderedHashRepartitionStream.cs
- DataGridCell.cs
- TypeDelegator.cs
- CodeNamespaceImport.cs
- HtmlInputButton.cs
- NamespaceQuery.cs
- NeutralResourcesLanguageAttribute.cs
- PersonalizationDictionary.cs
- BuildProvider.cs
- CollectionBase.cs
- RawContentTypeMapper.cs
- FileDialog.cs
- File.cs
- ResourceReferenceKeyNotFoundException.cs
- PeerObject.cs
- QualificationDataAttribute.cs
- _CookieModule.cs
- DomainConstraint.cs
- login.cs
- ArrayItemValue.cs
- ConfigurationValidatorAttribute.cs
- InkPresenter.cs
- ConnectorDragDropGlyph.cs
- XmlDataSourceView.cs
- ImmutableObjectAttribute.cs
- Cursor.cs
- baseaxisquery.cs
- LambdaCompiler.Unary.cs
- TextLine.cs
- ScriptComponentDescriptor.cs
- DoubleLinkList.cs
- BinaryOperationBinder.cs
- SynchronousReceiveBehavior.cs
- RegexMatch.cs
- LineServicesCallbacks.cs
- PixelShader.cs
- Timer.cs
- HtmlTitle.cs
- AuthorizationRuleCollection.cs
- ValidationPropertyAttribute.cs
- Queue.cs
- FullTrustAssemblyCollection.cs
- WebReferencesBuildProvider.cs
- HatchBrush.cs
- ScopelessEnumAttribute.cs
- ThrowHelper.cs
- DataBindingExpressionBuilder.cs
- AffineTransform3D.cs
- AddValidationError.cs
- XmlNamedNodeMap.cs
- Exception.cs
- NotImplementedException.cs
- Byte.cs
- ClientRuntimeConfig.cs
- SingleAnimationUsingKeyFrames.cs
- OleDbSchemaGuid.cs
- ComboBoxItem.cs
- SafeLocalMemHandle.cs
- ParserOptions.cs
- OperationPerformanceCounters.cs
- HttpStreamMessage.cs
- XmlIncludeAttribute.cs
- ComplexObject.cs
- RenderDataDrawingContext.cs
- DataExchangeServiceBinder.cs
- Run.cs
- WebPartZoneBase.cs
- AuthorizationContext.cs
- FlowDocumentReaderAutomationPeer.cs
- Scripts.cs
- ButtonChrome.cs
- PageSetupDialog.cs
- ReadOnlyDictionary.cs
- ImmutableCollection.cs
- SectionRecord.cs
- CodeBinaryOperatorExpression.cs
- ResourceReferenceExpressionConverter.cs
- MimeTypeAttribute.cs
- odbcmetadatacollectionnames.cs
- Accessible.cs
- Vector3DCollectionValueSerializer.cs
- ClientRuntimeConfig.cs
- GridViewCancelEditEventArgs.cs
- ProxyFragment.cs
- DbConnectionPoolCounters.cs
- CodeCatchClause.cs
- CfgParser.cs
- NullToBooleanConverter.cs
- TextBoxAutomationPeer.cs
- Parser.cs
- ProfileGroupSettingsCollection.cs
- HtmlInputRadioButton.cs
- X509Chain.cs
- ToolStripItemDataObject.cs
- SessionPageStatePersister.cs
- COM2PropertyPageUITypeConverter.cs
- FreeFormDragDropManager.cs
- CodeGenHelper.cs
- GeneralTransform3DGroup.cs