Code:
/ 4.0 / 4.0 / untmp / 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.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- PrinterUnitConvert.cs
- ErrorBehavior.cs
- LingerOption.cs
- GuidTagList.cs
- NoClickablePointException.cs
- SqlReferenceCollection.cs
- LostFocusEventManager.cs
- MorphHelpers.cs
- DebugInfoGenerator.cs
- CodeExporter.cs
- GCHandleCookieTable.cs
- WebPartManager.cs
- PnrpPermission.cs
- Ref.cs
- CodeCatchClauseCollection.cs
- Deflater.cs
- CryptoApi.cs
- TextRangeEdit.cs
- FunctionImportElement.cs
- ListBase.cs
- ApplicationTrust.cs
- ProcessHost.cs
- EnumConverter.cs
- MemoryStream.cs
- ImageBrush.cs
- ErrorFormatterPage.cs
- XmlSchemaInfo.cs
- FixedSOMPageElement.cs
- MulticastDelegate.cs
- StringComparer.cs
- XmlReaderSettings.cs
- SqlReferenceCollection.cs
- WindowsToolbar.cs
- initElementDictionary.cs
- RelatedPropertyManager.cs
- TypedElement.cs
- InlineCollection.cs
- SectionVisual.cs
- SafeNativeMemoryHandle.cs
- ProtectedProviderSettings.cs
- MasterPageCodeDomTreeGenerator.cs
- UInt64Converter.cs
- Faults.cs
- ExpandSegment.cs
- GridView.cs
- AttachmentCollection.cs
- InputBindingCollection.cs
- RelationshipEndMember.cs
- CopyAction.cs
- EntityDataSourceDataSelectionPanel.cs
- LocatorPartList.cs
- XmlChildNodes.cs
- HtmlControl.cs
- ECDiffieHellmanPublicKey.cs
- TextContainerChangedEventArgs.cs
- DebuggerAttributes.cs
- NotifyParentPropertyAttribute.cs
- SignatureConfirmationElement.cs
- DataGridViewColumn.cs
- SettingsPropertyCollection.cs
- ValueSerializerAttribute.cs
- SelectionRange.cs
- UnsafeNativeMethodsTablet.cs
- ObjectNotFoundException.cs
- PerfCounterSection.cs
- SoapCodeExporter.cs
- ItemCollection.cs
- MultiPropertyDescriptorGridEntry.cs
- SetterBase.cs
- QueryStringParameter.cs
- DataGridViewTextBoxCell.cs
- SeekableReadStream.cs
- MultiAsyncResult.cs
- MessageBox.cs
- OleDbReferenceCollection.cs
- ChtmlTextWriter.cs
- CrossSiteScriptingValidation.cs
- GB18030Encoding.cs
- IisTraceWebEventProvider.cs
- BridgeDataRecord.cs
- EncryptedKey.cs
- ResourceKey.cs
- BasicKeyConstraint.cs
- ObjectFullSpanRewriter.cs
- SelectingProviderEventArgs.cs
- ListItemsCollectionEditor.cs
- VersionUtil.cs
- XmlnsCache.cs
- OutputCacheSettings.cs
- TemplateModeChangedEventArgs.cs
- JoinTreeNode.cs
- WebBrowserPermission.cs
- CodeMemberField.cs
- ColorConvertedBitmap.cs
- NamespaceInfo.cs
- OleDbParameter.cs
- StringCollectionMarkupSerializer.cs
- ResourcesGenerator.cs
- SubtreeProcessor.cs
- Registry.cs