Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / Orcas / SP / 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
- BinaryConverter.cs
- Repeater.cs
- PenLineJoinValidation.cs
- AsynchronousChannelMergeEnumerator.cs
- ListenerTraceUtility.cs
- TPLETWProvider.cs
- DocumentReference.cs
- PagePropertiesChangingEventArgs.cs
- ParameterCollection.cs
- CompModSwitches.cs
- DriveNotFoundException.cs
- EFDataModelProvider.cs
- TablePattern.cs
- PenContexts.cs
- TextAdaptor.cs
- SoundPlayerAction.cs
- ProfileProvider.cs
- ElementUtil.cs
- TreeViewHitTestInfo.cs
- LocalBuilder.cs
- TypeSystemHelpers.cs
- HandlerBase.cs
- ConfigXmlComment.cs
- ListViewInsertedEventArgs.cs
- NamespaceList.cs
- FrameworkTextComposition.cs
- WebSysDisplayNameAttribute.cs
- C14NUtil.cs
- WindowsSysHeader.cs
- FillRuleValidation.cs
- DbConnectionPoolCounters.cs
- ControlBindingsCollection.cs
- DesignBindingEditor.cs
- KeyEventArgs.cs
- NonVisualControlAttribute.cs
- ToolTip.cs
- BaseAddressPrefixFilterElement.cs
- OdbcConnectionPoolProviderInfo.cs
- SqlStream.cs
- TypeToken.cs
- HWStack.cs
- IsolatedStorageFile.cs
- CodeAttributeArgument.cs
- RegexTree.cs
- TextDecoration.cs
- Literal.cs
- MetadataExporter.cs
- HyperLinkColumn.cs
- IisNotInstalledException.cs
- TypeInformation.cs
- ScriptingScriptResourceHandlerSection.cs
- CollectionBuilder.cs
- CounterSampleCalculator.cs
- ToolStripDropDownClosedEventArgs.cs
- Ops.cs
- TabControlEvent.cs
- EUCJPEncoding.cs
- TextDocumentView.cs
- Propagator.cs
- SizeAnimationUsingKeyFrames.cs
- SafeMarshalContext.cs
- XmlSchemaAny.cs
- AuthenticationSection.cs
- ProxyManager.cs
- HiddenFieldPageStatePersister.cs
- TimeSpanMinutesConverter.cs
- Inflater.cs
- FlowDocumentReader.cs
- QilTargetType.cs
- WindowsGrip.cs
- DecimalAnimationUsingKeyFrames.cs
- BlurEffect.cs
- Win32Native.cs
- ContainsRowNumberChecker.cs
- ObjectViewListener.cs
- SoapIncludeAttribute.cs
- StaticFileHandler.cs
- InternalUserCancelledException.cs
- DrawingGroup.cs
- NotifyInputEventArgs.cs
- ByteAnimation.cs
- AspProxy.cs
- Rect3DConverter.cs
- SupportsEventValidationAttribute.cs
- TextAnchor.cs
- ObsoleteAttribute.cs
- TypeSemantics.cs
- StreamingContext.cs
- TypeConverterAttribute.cs
- Convert.cs
- MSHTMLHost.cs
- MatrixTransform.cs
- WinEventQueueItem.cs
- Activity.cs
- StrokeFIndices.cs
- FileUtil.cs
- SqlXml.cs
- URL.cs
- DataGridViewCellStyleChangedEventArgs.cs
- AsymmetricCryptoHandle.cs