Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / clr / src / BCL / System / Security / Policy / Site.cs / 1305376 / Site.cs
// ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== //[....] // // // Site.cs // // Site is an IIdentity representing internet sites. // using System; using System.Diagnostics.Contracts; using System.Globalization; using System.Security.Permissions; using System.Security.Util; namespace System.Security.Policy { [Serializable] [System.Runtime.InteropServices.ComVisible(true)] public sealed class Site : EvidenceBase, IIdentityPermissionFactory { private SiteString m_name; public Site(String name) { if (name == null) throw new ArgumentNullException("name"); Contract.EndContractBlock(); m_name = new SiteString( name ); } private Site(SiteString name) { Contract.Assert(name != null); m_name = name; } public static Site CreateFromUrl( String url ) { return new Site(ParseSiteFromUrl(url)); } private static SiteString ParseSiteFromUrl( String name ) { URLString urlString = new URLString( name ); if (String.Compare( urlString.Scheme, "file", StringComparison.OrdinalIgnoreCase) == 0) throw new ArgumentException( Environment.GetResourceString( "Argument_InvalidSite" ) ); return new SiteString( new URLString( name ).Host ); } public String Name { get { return m_name.ToString(); } } internal SiteString GetSiteString() { return m_name; } public IPermission CreateIdentityPermission( Evidence evidence ) { return new SiteIdentityPermission( Name ); } public override bool Equals(Object o) { Site other = o as Site; if (other == null) { return false; } return String.Equals(Name, other.Name, StringComparison.OrdinalIgnoreCase); } public override int GetHashCode() { return Name.GetHashCode(); } public override EvidenceBase Clone() { return new Site(m_name); } public Object Copy() { return Clone(); } #if FEATURE_CAS_POLICY internal SecurityElement ToXml() { SecurityElement elem = new SecurityElement( "System.Security.Policy.Site" ); // If you hit this assert then most likely you are trying to change the name of this class. // This is ok as long as you change the hard coded string above and change the assert below. Contract.Assert( this.GetType().FullName.Equals( "System.Security.Policy.Site" ), "Class name changed!" ); elem.AddAttribute( "version", "1" ); if(m_name != null) elem.AddChild( new SecurityElement( "Name", m_name.ToString() ) ); return elem; } #endif // FEATURE_CAS_POLICY #if FEATURE_CAS_POLICY public override String ToString() { return ToXml().ToString(); } #endif // FEATURE_CAS_POLICY // INormalizeForIsolatedStorage is not implemented for startup perf // equivalent to INormalizeForIsolatedStorage.Normalize() internal Object Normalize() { return m_name.ToString().ToUpper(CultureInfo.InvariantCulture); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== //[....] // // // Site.cs // // Site is an IIdentity representing internet sites. // using System; using System.Diagnostics.Contracts; using System.Globalization; using System.Security.Permissions; using System.Security.Util; namespace System.Security.Policy { [Serializable] [System.Runtime.InteropServices.ComVisible(true)] public sealed class Site : EvidenceBase, IIdentityPermissionFactory { private SiteString m_name; public Site(String name) { if (name == null) throw new ArgumentNullException("name"); Contract.EndContractBlock(); m_name = new SiteString( name ); } private Site(SiteString name) { Contract.Assert(name != null); m_name = name; } public static Site CreateFromUrl( String url ) { return new Site(ParseSiteFromUrl(url)); } private static SiteString ParseSiteFromUrl( String name ) { URLString urlString = new URLString( name ); if (String.Compare( urlString.Scheme, "file", StringComparison.OrdinalIgnoreCase) == 0) throw new ArgumentException( Environment.GetResourceString( "Argument_InvalidSite" ) ); return new SiteString( new URLString( name ).Host ); } public String Name { get { return m_name.ToString(); } } internal SiteString GetSiteString() { return m_name; } public IPermission CreateIdentityPermission( Evidence evidence ) { return new SiteIdentityPermission( Name ); } public override bool Equals(Object o) { Site other = o as Site; if (other == null) { return false; } return String.Equals(Name, other.Name, StringComparison.OrdinalIgnoreCase); } public override int GetHashCode() { return Name.GetHashCode(); } public override EvidenceBase Clone() { return new Site(m_name); } public Object Copy() { return Clone(); } #if FEATURE_CAS_POLICY internal SecurityElement ToXml() { SecurityElement elem = new SecurityElement( "System.Security.Policy.Site" ); // If you hit this assert then most likely you are trying to change the name of this class. // This is ok as long as you change the hard coded string above and change the assert below. Contract.Assert( this.GetType().FullName.Equals( "System.Security.Policy.Site" ), "Class name changed!" ); elem.AddAttribute( "version", "1" ); if(m_name != null) elem.AddChild( new SecurityElement( "Name", m_name.ToString() ) ); return elem; } #endif // FEATURE_CAS_POLICY #if FEATURE_CAS_POLICY public override String ToString() { return ToXml().ToString(); } #endif // FEATURE_CAS_POLICY // INormalizeForIsolatedStorage is not implemented for startup perf // equivalent to INormalizeForIsolatedStorage.Normalize() internal Object Normalize() { return m_name.ToString().ToUpper(CultureInfo.InvariantCulture); } } } // 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
- OLEDB_Enum.cs
- OverlappedAsyncResult.cs
- ThousandthOfEmRealDoubles.cs
- DrawingImage.cs
- BindingCollection.cs
- OleDbWrapper.cs
- ValidationManager.cs
- DataGridViewColumnDividerDoubleClickEventArgs.cs
- WSSecurityOneDotZeroReceiveSecurityHeader.cs
- DBDataPermission.cs
- oledbconnectionstring.cs
- UpdateTranslator.cs
- KeyInfo.cs
- StatusStrip.cs
- ProfileGroupSettings.cs
- WebPartVerbCollection.cs
- updateconfighost.cs
- processwaithandle.cs
- CompositeControl.cs
- EnumerableRowCollectionExtensions.cs
- TextEndOfParagraph.cs
- SQLGuidStorage.cs
- DocumentPageHost.cs
- Environment.cs
- URLAttribute.cs
- ItemCollection.cs
- SafeProcessHandle.cs
- XPathDocumentIterator.cs
- RelationshipNavigation.cs
- RectangleGeometry.cs
- GeneratedCodeAttribute.cs
- ThreadStaticAttribute.cs
- DictionaryEntry.cs
- RuntimeTransactionHandle.cs
- DefaultBindingPropertyAttribute.cs
- Solver.cs
- Rfc2898DeriveBytes.cs
- DataGridTableCollection.cs
- GenericTextProperties.cs
- StringReader.cs
- cookiecontainer.cs
- ToolStripProfessionalLowResolutionRenderer.cs
- TimestampInformation.cs
- CompilationSection.cs
- ElementHost.cs
- XmlSubtreeReader.cs
- HelpEvent.cs
- DayRenderEvent.cs
- ComplexType.cs
- RTLAwareMessageBox.cs
- PowerStatus.cs
- TemplateBaseAction.cs
- EndPoint.cs
- DataGridTableCollection.cs
- SqlNode.cs
- followingsibling.cs
- SelectedGridItemChangedEvent.cs
- SiteMapNodeItem.cs
- SqlDataSourceCommandParser.cs
- SmtpException.cs
- DescendantOverDescendantQuery.cs
- WebEventTraceProvider.cs
- SerializationEventsCache.cs
- Button.cs
- XPathAncestorQuery.cs
- TextEditorCharacters.cs
- AdornerDecorator.cs
- TreeView.cs
- ListView.cs
- DetailsViewInsertEventArgs.cs
- ClientBuildManagerCallback.cs
- ClrProviderManifest.cs
- ping.cs
- SHA384.cs
- FixedFindEngine.cs
- ImageDrawing.cs
- SynchronizedDispatch.cs
- List.cs
- CdpEqualityComparer.cs
- KeyInstance.cs
- GlobalizationAssembly.cs
- SendMailErrorEventArgs.cs
- COM2PictureConverter.cs
- TextBox.cs
- SvcFileManager.cs
- AnnotationElement.cs
- HMACSHA256.cs
- _Connection.cs
- MD5CryptoServiceProvider.cs
- EventLogPermissionAttribute.cs
- DSACryptoServiceProvider.cs
- XmlParserContext.cs
- Expressions.cs
- ServicesExceptionNotHandledEventArgs.cs
- ViewGenResults.cs
- Resources.Designer.cs
- WebBrowserNavigatedEventHandler.cs
- RequestCache.cs
- MDIWindowDialog.cs
- SerializationEventsCache.cs