Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / xsp / System / Extensions / ApplicationServices / RoleService.cs / 1305376 / 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; [ AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required), 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; [ AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required), 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
- TabPage.cs
- CompoundFileStorageReference.cs
- LayoutEngine.cs
- Point4DConverter.cs
- Interlocked.cs
- CodeAccessPermission.cs
- WinInetCache.cs
- IPAddressCollection.cs
- CalendarDataBindingHandler.cs
- DocumentPageView.cs
- DataMemberFieldEditor.cs
- IPAddressCollection.cs
- SQLDouble.cs
- DataKeyArray.cs
- RightsManagementPermission.cs
- OpCopier.cs
- UIElementIsland.cs
- ManagementEventArgs.cs
- TypeDescriptorContext.cs
- SocketElement.cs
- Pen.cs
- _AcceptOverlappedAsyncResult.cs
- AnnotationAuthorChangedEventArgs.cs
- ComponentManagerBroker.cs
- Content.cs
- Columns.cs
- Qualifier.cs
- InputElement.cs
- OleDbTransaction.cs
- ExpressionQuoter.cs
- BackStopAuthenticationModule.cs
- printdlgexmarshaler.cs
- SBCSCodePageEncoding.cs
- ContextBase.cs
- DataGridItemAttachedStorage.cs
- Rect3D.cs
- VarRemapper.cs
- ManifestResourceInfo.cs
- DataGridViewCellValueEventArgs.cs
- Triplet.cs
- GiveFeedbackEvent.cs
- RemoteWebConfigurationHostStream.cs
- XmlText.cs
- WinInetCache.cs
- RTLAwareMessageBox.cs
- UTF8Encoding.cs
- UserControlAutomationPeer.cs
- QuaternionValueSerializer.cs
- CodeVariableReferenceExpression.cs
- GenericTypeParameterBuilder.cs
- ActivityScheduledQuery.cs
- MappingItemCollection.cs
- Renderer.cs
- SynchronizedDispatch.cs
- shaperfactoryquerycacheentry.cs
- XmlDictionaryString.cs
- BoundPropertyEntry.cs
- Wizard.cs
- BuildManagerHost.cs
- ExtractorMetadata.cs
- CngAlgorithm.cs
- Size.cs
- PagesSection.cs
- ImageMapEventArgs.cs
- KoreanCalendar.cs
- TitleStyle.cs
- TrackBarRenderer.cs
- XmlHierarchyData.cs
- Tile.cs
- Expression.cs
- CompoundFileStreamReference.cs
- MenuEventArgs.cs
- VirtualPath.cs
- DataGridViewCellCollection.cs
- ChildTable.cs
- TextTreeUndo.cs
- TagPrefixCollection.cs
- OdbcConnectionString.cs
- TextBox.cs
- ViewSimplifier.cs
- SortQuery.cs
- InstanceOwnerException.cs
- StringUtil.cs
- WebPartCollection.cs
- GridViewUpdateEventArgs.cs
- IdentifierCreationService.cs
- AbstractSvcMapFileLoader.cs
- XmlNamespaceMapping.cs
- ListMarkerSourceInfo.cs
- MinMaxParagraphWidth.cs
- DefaultMemberAttribute.cs
- processwaithandle.cs
- ComponentChangingEvent.cs
- Thread.cs
- DashStyle.cs
- WebHttpSecurityModeHelper.cs
- SimpleWebHandlerParser.cs
- SimpleTypeResolver.cs
- BitmapEffect.cs
- TextSpanModifier.cs