Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / ndp / fx / src / xsp / System / Web / Extensions / ApplicationServices / RoleService.cs / 1 / RoleService.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Web.ApplicationServices { using System; using System.Diagnostics.CodeAnalysis; using System.ServiceModel; using System.ServiceModel.Activation; using System.ServiceModel.Configuration; using System.Runtime.Serialization; using System.Web; using System.Web.Security; using System.Web.Configuration; using System.Web.Management; using System.Web.Resources; using System.Security.Principal; using System.Web.Hosting; using System.Threading; using System.Configuration.Provider; using System.Security.Permissions; [ AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required), AspNetHostingPermission(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal), AspNetHostingPermission(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal), ServiceContract(Namespace = "http://asp.net/ApplicationServices/v200"), ServiceBehavior(Namespace="http://asp.net/ApplicationServices/v200", InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Multiple) ] public class RoleService { private static object _selectingProviderEventHandlerLock = new object(); private static EventHandler_selectingProvider; public static event EventHandler SelectingProvider { add { lock (_selectingProviderEventHandlerLock) { _selectingProvider += value; } } remove { lock (_selectingProviderEventHandlerLock) { _selectingProvider -= value; } } } private static void EnsureProviderEnabled() { if (!Roles.Enabled) { throw new ProviderException(AtlasWeb.RoleService_RolesFeatureNotEnabled); } } private RoleProvider GetRoleProvider(IPrincipal user) { string providerName = Roles.Provider.Name; SelectingProviderEventArgs args = new SelectingProviderEventArgs(user, providerName); OnSelectingProvider(args); providerName = args.ProviderName; RoleProvider provider = Roles.Providers[providerName]; if (provider == null) { throw new ProviderException(AtlasWeb.RoleService_RoleProviderNotFound); } return provider; } [OperationContract] public string[] GetRolesForCurrentUser() { try { ApplicationServiceHelper.EnsureRoleServiceEnabled(); EnsureProviderEnabled(); IPrincipal user = ApplicationServiceHelper.GetCurrentUser(HttpContext.Current); string username = ApplicationServiceHelper.GetUserName(user); RoleProvider provider = GetRoleProvider(user); return provider.GetRolesForUser(username); } catch (Exception e) { LogException(e); throw; } } [OperationContract] public bool IsCurrentUserInRole(string role) { if (role == null) { throw new ArgumentNullException("role"); } try { ApplicationServiceHelper.EnsureRoleServiceEnabled(); EnsureProviderEnabled(); IPrincipal user = ApplicationServiceHelper.GetCurrentUser(HttpContext.Current); string username = ApplicationServiceHelper.GetUserName(user); RoleProvider provider = GetRoleProvider(user); return provider.IsUserInRole(username, role); } catch (Exception e) { LogException(e); throw; } } private void LogException(Exception e) { WebServiceErrorEvent errorevent = new WebServiceErrorEvent(AtlasWeb.UnhandledExceptionEventLogMessage, this, e); errorevent.Raise(); } private void OnSelectingProvider(SelectingProviderEventArgs e) { EventHandler handler = _selectingProvider; if (handler != null) { handler(this, e); } } //hiding public constructor internal RoleService() { } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ // // Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Web.ApplicationServices { using System; using System.Diagnostics.CodeAnalysis; using System.ServiceModel; using System.ServiceModel.Activation; using System.ServiceModel.Configuration; using System.Runtime.Serialization; using System.Web; using System.Web.Security; using System.Web.Configuration; using System.Web.Management; using System.Web.Resources; using System.Security.Principal; using System.Web.Hosting; using System.Threading; using System.Configuration.Provider; using System.Security.Permissions; [ AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required), AspNetHostingPermission(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal), AspNetHostingPermission(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal), ServiceContract(Namespace = "http://asp.net/ApplicationServices/v200"), ServiceBehavior(Namespace="http://asp.net/ApplicationServices/v200", InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Multiple) ] public class RoleService { private static object _selectingProviderEventHandlerLock = new object(); private static EventHandler_selectingProvider; public static event EventHandler SelectingProvider { add { lock (_selectingProviderEventHandlerLock) { _selectingProvider += value; } } remove { lock (_selectingProviderEventHandlerLock) { _selectingProvider -= value; } } } private static void EnsureProviderEnabled() { if (!Roles.Enabled) { throw new ProviderException(AtlasWeb.RoleService_RolesFeatureNotEnabled); } } private RoleProvider GetRoleProvider(IPrincipal user) { string providerName = Roles.Provider.Name; SelectingProviderEventArgs args = new SelectingProviderEventArgs(user, providerName); OnSelectingProvider(args); providerName = args.ProviderName; RoleProvider provider = Roles.Providers[providerName]; if (provider == null) { throw new ProviderException(AtlasWeb.RoleService_RoleProviderNotFound); } return provider; } [OperationContract] public string[] GetRolesForCurrentUser() { try { ApplicationServiceHelper.EnsureRoleServiceEnabled(); EnsureProviderEnabled(); IPrincipal user = ApplicationServiceHelper.GetCurrentUser(HttpContext.Current); string username = ApplicationServiceHelper.GetUserName(user); RoleProvider provider = GetRoleProvider(user); return provider.GetRolesForUser(username); } catch (Exception e) { LogException(e); throw; } } [OperationContract] public bool IsCurrentUserInRole(string role) { if (role == null) { throw new ArgumentNullException("role"); } try { ApplicationServiceHelper.EnsureRoleServiceEnabled(); EnsureProviderEnabled(); IPrincipal user = ApplicationServiceHelper.GetCurrentUser(HttpContext.Current); string username = ApplicationServiceHelper.GetUserName(user); RoleProvider provider = GetRoleProvider(user); return provider.IsUserInRole(username, role); } catch (Exception e) { LogException(e); throw; } } private void LogException(Exception e) { WebServiceErrorEvent errorevent = new WebServiceErrorEvent(AtlasWeb.UnhandledExceptionEventLogMessage, this, e); errorevent.Raise(); } private void OnSelectingProvider(SelectingProviderEventArgs e) { EventHandler handler = _selectingProvider; if (handler != null) { handler(this, e); } } //hiding public constructor internal RoleService() { } } } // 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
- AsyncResult.cs
- XsltArgumentList.cs
- LayeredChannelFactory.cs
- CatalogPart.cs
- UrlPath.cs
- Debug.cs
- XmlSchemaExternal.cs
- AccessViolationException.cs
- BridgeDataReader.cs
- CodeDomDecompiler.cs
- Label.cs
- Descriptor.cs
- Token.cs
- SimpleTypeResolver.cs
- DataSetUtil.cs
- PropertyIDSet.cs
- CodePageUtils.cs
- Emitter.cs
- Vertex.cs
- SqlDataSourceDesigner.cs
- DesignerValidatorAdapter.cs
- WebPartDescription.cs
- DbProviderFactories.cs
- CancellationTokenSource.cs
- BlurBitmapEffect.cs
- LinkButton.cs
- Asn1IntegerConverter.cs
- TrustLevelCollection.cs
- OracleCommandBuilder.cs
- XmlAggregates.cs
- IdentityModelStringsVersion1.cs
- DocumentViewerAutomationPeer.cs
- Char.cs
- StringAnimationBase.cs
- InputScopeAttribute.cs
- Geometry.cs
- StagingAreaInputItem.cs
- SettingsPropertyNotFoundException.cs
- Image.cs
- NumericUpDownAccelerationCollection.cs
- XmlSerializerSection.cs
- TypedTableBase.cs
- BamlTreeMap.cs
- EllipticalNodeOperations.cs
- Int64.cs
- MaskedTextProvider.cs
- PtsHelper.cs
- DesignSurfaceCollection.cs
- ToolStripDropDownClosedEventArgs.cs
- BinaryConverter.cs
- StorageScalarPropertyMapping.cs
- MenuItemBindingCollection.cs
- DataGrid.cs
- MessageBox.cs
- Logging.cs
- PageTheme.cs
- BamlResourceDeserializer.cs
- FixedStringLookup.cs
- UidPropertyAttribute.cs
- EntityDataSource.cs
- XmlSchemaElement.cs
- GeometryConverter.cs
- TreeView.cs
- ObjectToken.cs
- HttpHostedTransportConfiguration.cs
- XmlSchemaGroup.cs
- InboundActivityHelper.cs
- TypedReference.cs
- TableItemProviderWrapper.cs
- xdrvalidator.cs
- IpcChannel.cs
- MenuAutoFormat.cs
- DoubleMinMaxAggregationOperator.cs
- CodeMemberProperty.cs
- ItemList.cs
- OleDbSchemaGuid.cs
- RouteParameter.cs
- GenericsNotImplementedException.cs
- RMPublishingDialog.cs
- CodeComment.cs
- CatalogZoneBase.cs
- XmlAnyElementAttribute.cs
- PasswordBox.cs
- TraceUtils.cs
- MethodExpr.cs
- RequestSecurityTokenResponse.cs
- CompressionTransform.cs
- CodeFieldReferenceExpression.cs
- ScrollableControlDesigner.cs
- XmlSecureResolver.cs
- HtmlInputRadioButton.cs
- SmiXetterAccessMap.cs
- CheckPair.cs
- ElementMarkupObject.cs
- DiagnosticsConfiguration.cs
- XmlAttributeProperties.cs
- WindowsListBox.cs
- ApplicationCommands.cs
- DiscoveryReference.cs
- SchemaMapping.cs