Code:
/ DotNET / DotNET / 8.0 / untmp / Orcas / RTM / 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.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- WindowsStreamSecurityElement.cs
- AmbientProperties.cs
- COM2Enum.cs
- PostBackOptions.cs
- OleDbError.cs
- SqlDataSourceFilteringEventArgs.cs
- RawStylusInputCustomDataList.cs
- SiteMapDataSourceView.cs
- Renderer.cs
- XmlLanguage.cs
- Rotation3DAnimationUsingKeyFrames.cs
- TaskFormBase.cs
- InvariantComparer.cs
- ModelEditingScope.cs
- IndicShape.cs
- GroupLabel.cs
- InputLanguageCollection.cs
- RelationshipNavigation.cs
- SafePointer.cs
- UnsafeNativeMethods.cs
- COMException.cs
- _ContextAwareResult.cs
- XmlAutoDetectWriter.cs
- SurrogateEncoder.cs
- WebContext.cs
- WindowCollection.cs
- ReliableSessionElement.cs
- ElementFactory.cs
- HttpCookie.cs
- DataGridViewTextBoxColumn.cs
- WindowsListBox.cs
- XmlHierarchicalEnumerable.cs
- MetadataItemEmitter.cs
- ColumnClickEvent.cs
- TypeConverterHelper.cs
- XmlAttribute.cs
- ModelServiceImpl.cs
- TextDecorationCollectionConverter.cs
- ResourceBinder.cs
- Visual.cs
- SqlDesignerDataSourceView.cs
- CompiledIdentityConstraint.cs
- DataTemplateKey.cs
- ValidatedControlConverter.cs
- Nullable.cs
- SizeAnimation.cs
- CodeCatchClauseCollection.cs
- OAVariantLib.cs
- HostExecutionContextManager.cs
- Site.cs
- MobileControlDesigner.cs
- IconHelper.cs
- CodeAccessPermission.cs
- VBIdentifierName.cs
- BulletedList.cs
- CheckBoxPopupAdapter.cs
- Axis.cs
- ParallelDesigner.cs
- AvTraceDetails.cs
- MailWebEventProvider.cs
- XmlNodeList.cs
- ObjectContextServiceProvider.cs
- ExpressionLexer.cs
- DetailsViewDeleteEventArgs.cs
- Ray3DHitTestResult.cs
- SchemaImporterExtensionElementCollection.cs
- EncryptedKey.cs
- CodeVariableReferenceExpression.cs
- Error.cs
- FixedHyperLink.cs
- SynchronizedDispatch.cs
- CompiledAction.cs
- rsa.cs
- SecurityUtils.cs
- ActivityDesigner.cs
- DataKey.cs
- Int32RectValueSerializer.cs
- KeyboardInputProviderAcquireFocusEventArgs.cs
- RpcResponse.cs
- StrongNameHelpers.cs
- SoapSchemaMember.cs
- WindowsFormsHelpers.cs
- ProfileGroupSettingsCollection.cs
- FixUp.cs
- ScriptReferenceBase.cs
- PageThemeParser.cs
- WebExceptionStatus.cs
- RichTextBoxDesigner.cs
- XmlToDatasetMap.cs
- GridItemProviderWrapper.cs
- HitTestParameters.cs
- Attributes.cs
- CaseInsensitiveComparer.cs
- MaskedTextBox.cs
- LinkLabel.cs
- DataObjectEventArgs.cs
- DataGridViewAccessibleObject.cs
- itemelement.cs
- ManagedFilter.cs
- EncryptedData.cs