Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / Orcas / QFE / 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
- TreeViewEvent.cs
- ProcessThread.cs
- MediaTimeline.cs
- PanelDesigner.cs
- Oid.cs
- ContentPropertyAttribute.cs
- FontFaceLayoutInfo.cs
- SoapIncludeAttribute.cs
- FormViewActionList.cs
- HiddenFieldPageStatePersister.cs
- LogicalCallContext.cs
- MatcherBuilder.cs
- ApplicationFileParser.cs
- FamilyCollection.cs
- webbrowsersite.cs
- Expander.cs
- ConfigViewGenerator.cs
- ObjectComplexPropertyMapping.cs
- ObfuscationAttribute.cs
- GeneralTransform.cs
- ThrowHelper.cs
- Scheduler.cs
- DbgCompiler.cs
- RowUpdatedEventArgs.cs
- CodePrimitiveExpression.cs
- ImageCodecInfo.cs
- BinaryFormatterSinks.cs
- RadioButton.cs
- Property.cs
- DetailsViewUpdateEventArgs.cs
- Point4DConverter.cs
- FormViewInsertEventArgs.cs
- AdornerLayer.cs
- ProgressBarRenderer.cs
- ModuleBuilderData.cs
- UserControlFileEditor.cs
- SecurityContextKeyIdentifierClause.cs
- CurrentChangingEventManager.cs
- RequiredAttributeAttribute.cs
- ISSmlParser.cs
- NavigatingCancelEventArgs.cs
- WebPartsPersonalizationAuthorization.cs
- GeneralTransform.cs
- DeploymentExceptionMapper.cs
- Properties.cs
- DesignerActionGlyph.cs
- DbConnectionOptions.cs
- BuilderInfo.cs
- _SecureChannel.cs
- DataGridColumnHeadersPresenter.cs
- HttpBrowserCapabilitiesWrapper.cs
- MachineKey.cs
- DesignerOptionService.cs
- LocalizabilityAttribute.cs
- NullRuntimeConfig.cs
- FixedSOMTableRow.cs
- DataGridColumnHeadersPresenterAutomationPeer.cs
- ZipIOLocalFileBlock.cs
- DashStyle.cs
- ObjectSpanRewriter.cs
- WebPartManager.cs
- RepeatInfo.cs
- EncoderNLS.cs
- shaperfactory.cs
- ProfileSection.cs
- safemediahandle.cs
- SendDesigner.xaml.cs
- SHA1CryptoServiceProvider.cs
- StylusDevice.cs
- ActivationWorker.cs
- InternalRelationshipCollection.cs
- MailAddressCollection.cs
- GZipStream.cs
- SchemaAttDef.cs
- ApplicationCommands.cs
- ReadOnlyHierarchicalDataSource.cs
- FormsAuthenticationCredentials.cs
- TableLayoutStyle.cs
- RayMeshGeometry3DHitTestResult.cs
- MatchingStyle.cs
- MapPathBasedVirtualPathProvider.cs
- SmiRecordBuffer.cs
- StringExpressionSet.cs
- StylusPointPropertyInfoDefaults.cs
- WbemProvider.cs
- AgileSafeNativeMemoryHandle.cs
- LineUtil.cs
- WebPartConnectionsEventArgs.cs
- FrameSecurityDescriptor.cs
- SqlOuterApplyReducer.cs
- DesignerHelpers.cs
- XmlSchemaImporter.cs
- Simplifier.cs
- PersonalizationStateInfoCollection.cs
- TouchDevice.cs
- SamlAuthorityBinding.cs
- WindowsListBox.cs
- AssemblyCache.cs
- DataGridPagerStyle.cs
- RangeValuePattern.cs