コード例 #1
0
ファイル: identitysection.cs プロジェクト: zhimaqiao51/docs
        public UsingIdentitySection()
        {
// Process the selection.
            try
            {
// <Snippet1>
// Get the Web application configuration.
                System.Configuration.Configuration configuration = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("/aspnetTest");

// Get the section.
                System.Web.Configuration.IdentitySection identitySection = (System.Web.Configuration.IdentitySection)configuration.GetSection("system.web/identity");
// </Snippet1>


// <Snippet2>
// Create a new IdentitySection object.
                System.Web.Configuration.IdentitySection newidentitySection = new System.Web.Configuration.IdentitySection();
// </Snippet2>


// <Snippet3>
// Get the Password property value.
                string currentPassword = identitySection.Password;

// Set the Password property value.
                identitySection.Password = "******";
// </Snippet3>


// <Snippet4>
// Get the UserName property value.
                string currentUserName = identitySection.UserName;

// Set the UserName property value.
                identitySection.UserName = "******";
// </Snippet4>


// <Snippet5>
// Get the Impersonate property value.
                bool currentImpersonate = identitySection.Impersonate;

// Set the Impersonate property to true.
                identitySection.Impersonate = true;
// </Snippet5>
            }
            catch (Exception e)
            {
// Unknown error.
                Console.WriteLine("Error" + e.ToString());
            }
        }
コード例 #2
0
        protected override void Unmerge(ConfigurationElement sourceElement, ConfigurationElement parentElement, ConfigurationSaveMode saveMode)
        {
            base.Unmerge(sourceElement, parentElement, saveMode);
            IdentitySection section = sourceElement as IdentitySection;

            if (this.Impersonate != section.Impersonate)
            {
                this.Impersonate = section.Impersonate;
            }
            if (this.Impersonate && (section.ElementInformation.Properties[_propUserName.Name].IsModified || section.ElementInformation.Properties[_propPassword.Name].IsModified))
            {
                this.UserName = section.UserName;
                this.Password = section.Password;
            }
        }
コード例 #3
0
        protected override void Reset(ConfigurationElement parentElement)
        {
            base.Reset(parentElement);
            IdentitySection section = parentElement as IdentitySection;

            if (section != null)
            {
                this._impersonateTokenRef = section._impersonateTokenRef;
                if (this.Impersonate)
                {
                    this.UserName             = null;
                    this.Password             = null;
                    this._impersonateTokenRef = new ImpersonateTokenRef(IntPtr.Zero);
                }
                this.impersonateCached     = false;
                this._credentialsValidated = false;
            }
        }
コード例 #4
0
ファイル: IdentitySection.cs プロジェクト: dox0/DotNet471RS3
        protected override void Reset(ConfigurationElement parentElement)
        {
            base.Reset(parentElement);
            IdentitySection parent = parentElement as IdentitySection;

            if (parent != null)
            {
                _impersonateTokenRef = parent._impersonateTokenRef;
                // No partial overrides
                if (Impersonate)
                {
                    UserName             = null;
                    Password             = null;
                    _impersonateTokenRef = new ImpersonateTokenRef(IntPtr.Zero);
                }
                impersonateCached     = false; // We don't want to cache the parent's value!
                _credentialsValidated = false;
            }
        }
コード例 #5
0
ファイル: IdentitySection.cs プロジェクト: dox0/DotNet471RS3
        protected override void Unmerge(ConfigurationElement sourceElement,
                                        ConfigurationElement parentElement,
                                        ConfigurationSaveMode saveMode)
        {
            base.Unmerge(sourceElement, parentElement, saveMode); // do this to unmerge locks
            IdentitySection source = sourceElement as IdentitySection;

            if (Impersonate != source.Impersonate) // this will not be copied by unmerge if it is the same as parent
            {
                Impersonate = source.Impersonate;  // If it is different than expected make sure it is set or validation
            }                                      // will be missed
            // this section does not inherit in the same manner since partial overrides are not permitted
            if (Impersonate)                       // was impersonate set in the merge
            {
                if (source.ElementInformation.Properties[_propUserName.Name].IsModified ||
                    source.ElementInformation.Properties[_propPassword.Name].IsModified)
                {
                    UserName = source.UserName;
                    Password = source.Password;
                }
            }
        }
コード例 #6
0
 private void GetApplicationIdentity() {
     // if the explicit impersonation is set, use it instead of UNC identity
     try {
         IdentitySection c = RuntimeConfig.GetAppConfig().Identity;
         if (c.Impersonate && c.ImpersonateToken != IntPtr.Zero) {
             _appIdentity = c;
             _appIdentityToken = c.ImpersonateToken;
         }
         else {
             _appIdentityToken = _configToken;
         }
         _appIdentityTokenSet = true;
     }
     catch {
     }
 }
 private void GetApplicationIdentity()
 {
     try
     {
         IdentitySection identity = RuntimeConfig.GetAppConfig().Identity;
         if (identity.Impersonate && (identity.ImpersonateToken != IntPtr.Zero))
         {
             this._appIdentity = identity;
             this._appIdentityToken = identity.ImpersonateToken;
         }
         else
         {
             this._appIdentityToken = this._configToken;
         }
         this._appIdentityTokenSet = true;
     }
     catch
     {
     }
 }