UnauthorizedAccessException when updating a directory service entry from ASP.NET
- From: "Andrew Jocelyn" <j055@xxxxxxxxxxxxxxxx>
- Date: Wed, 15 Apr 2009 17:21:01 +0100
Hi
When I run this code from a ASP.NET website I get an
"System.UnauthorizedAccessException: General access denied error
" message when the Invoke method is called. The WindowsIdentity.GetCurrent()
is in the local administrator group. I tried running this with the <identity
impersonate="true"/> set i nthe web.config file but get the same error. The
OS is Windows Server 2008 x64, IIS 7.
var identity = WindowsIdentity.GetCurrent();
if (identity != null) Debug.WriteLine(identity.Name);
if (identity != null)
{
WindowsImpersonationContext impersonationContext =
identity.Impersonate();
//Insert your code that runs under the security context of the
authenticating user here.
const string name = "test.sp";
const string oldPassword = "oldpassword";
const string newPassword = "newpassword";
string username = string.Format(@"{0}\{1}",
Environment.MachineName, name);
var entry = new DirectoryEntry(string.Format("WinNT://{0}/{1},
user", Environment.MachineName, name),
username, oldPassword,
AuthenticationTypes.Secure);
entry.Invoke("ChangePassword", new object[] { oldPassword,
newPassword });
impersonationContext.Undo();
}
I want to run this code in a SharePoint webpart, so logged in users to
Sharepoint can change their own password essentially. Also I want to be able
to do the same thing with Active Directories.
Can you tell me why this doesn't work and what my options are?
Many thanks
Andrew
.
- Follow-Ups:
- RE: UnauthorizedAccessException when updating a directory service entry from ASP.NET
- From: Allen Chen [MSFT]
- Re: UnauthorizedAccessException when updating a directory service entry from ASP.NET
- From: Alexey Smirnov
- RE: UnauthorizedAccessException when updating a directory service entry from ASP.NET
- Prev by Date: Re: Published app doesn't work; what did I forget?
- Next by Date: Not another "could not create type 'blah'" thread
- Previous by thread: solution design - I'm stuck
- Next by thread: Re: UnauthorizedAccessException when updating a directory service entry from ASP.NET
- Index(es):