Problem with directoryServices and authentication

  • Thread starter Thread starter turbon
  • Start date Start date
T

turbon

Hello,
I am writing code, which will copy webServices from one IIS 6.0
webserver to another and using DirentoryServices to achieve this
purpose. And I have problems with authentication - I get an error
whenever I try to read properties of DirectoryEntry object. I had same
problems when I was using WMI, but there setting
ConnectionOptions co = new ConnectionOptions();
co.Authentication = AuthenticationLevel.PacketPrivacy;
solved the problem.
So perhaps a question would be - how can I set AuthenticationLevel to
PacketPrivacy, when I am using DirectoryServices?
 
| Hello,
| I am writing code, which will copy webServices from one IIS 6.0
| webserver to another and using DirentoryServices to achieve this
| purpose. And I have problems with authentication - I get an error
| whenever I try to read properties of DirectoryEntry object. I had same
| problems when I was using WMI, but there setting
| ConnectionOptions co = new ConnectionOptions();
| co.Authentication = AuthenticationLevel.PacketPrivacy;
| solved the problem.
| So perhaps a question would be - how can I set AuthenticationLevel to
| PacketPrivacy, when I am using DirectoryServices?
|

Check the AuthenticationTypes enum in System.DirectoryServices. If you are
binding to the IIS metadata you need at least
AuthenticationTypes.Encryption.


Willy.
 
WEll, I am using
AuthenticationType = AuthenticationTypes.Secure |
AuthenticationTypes.Signing | AuthenticationTypes.Encryption |
AuthenticationTypes.Delegation
but this does not work. Any other ideas?
 
Now I am starting to doubt that it's the authentication rpoblem....

the code just does not work....

here is the code:

public class WSMigration
{
private string srcServer,dstServer;

public WSMigration(string srcServer, string dstServer)
{
this.srcServer = srcServer;
this.dstServer=dstServer;
}

public void MigrateSettings()
{
DirectoryEntry W3SVC = new DirectoryEntry("IIS://" + srcServer);
W3SVC.AuthenticationType = AuthenticationTypes.Encryption;
this.SearchRelatedSettings(W3SVC);
}

private void SearchRelatedSettings(DirectoryEntry ent)
{
ent.AuthenticationType = AuthenticationTypes.Encryption;
foreach (DirectoryEntry n in ent.Children)
{
n.AuthenticationType = AuthenticationTypes.Encryption;
if(n.Name.ToLower().Replace("bt","tb") != n.Name.ToLower())
{
this.CopyWithHierarchy(n);
}
}

private DirectoryEntry CopyWithHierarchy(DirectoryEntry source)
{
if (source.Parent.Name.ToLower() == "w3svc"/*srcServer.ToLower()*/)
{
DirectoryEntry par = new DirectoryEntry("IIS://" + dstServer +
"/W3SVC");
DirectoryEntry de = source.CopyTo(par);
par.CommitChanges();
return de;
}
else
{
return source.CopyTo(this.CopyWithHierarchy(source.Parent));
}
}

public void MigrateFiles()
{
//Copies all neccesary files
}
}

I'd be very gratefull if someone could review this.
 
| the code just does not work....
is of little help here, please be more specific. Where does it fail, any
exceptions.. stacktraces..?

Willy.

| Now I am starting to doubt that it's the authentication rpoblem....
|
| the code just does not work....
|
| here is the code:
|
| public class WSMigration
| {
| private string srcServer,dstServer;
|
| public WSMigration(string srcServer, string dstServer)
| {
| this.srcServer = srcServer;
| this.dstServer=dstServer;
| }
|
| public void MigrateSettings()
| {
| DirectoryEntry W3SVC = new DirectoryEntry("IIS://" + srcServer);
| W3SVC.AuthenticationType = AuthenticationTypes.Encryption;
| this.SearchRelatedSettings(W3SVC);
| }
|
| private void SearchRelatedSettings(DirectoryEntry ent)
| {
| ent.AuthenticationType = AuthenticationTypes.Encryption;
| foreach (DirectoryEntry n in ent.Children)
| {
| n.AuthenticationType = AuthenticationTypes.Encryption;
| if(n.Name.ToLower().Replace("bt","tb") != n.Name.ToLower())
| {
| this.CopyWithHierarchy(n);
| }
| }
|
| private DirectoryEntry CopyWithHierarchy(DirectoryEntry source)
| {
| if (source.Parent.Name.ToLower() == "w3svc"/*srcServer.ToLower()*/)
| {
| DirectoryEntry par = new DirectoryEntry("IIS://" + dstServer +
| "/W3SVC");
| DirectoryEntry de = source.CopyTo(par);
| par.CommitChanges();
| return de;
| }
| else
| {
| return source.CopyTo(this.CopyWithHierarchy(source.Parent));
| }
| }
|
| public void MigrateFiles()
| {
| //Copies all neccesary files
| }
| }
|
| I'd be very gratefull if someone could review this.
|
 
Oh, sorry, forgot that.
So it fails in method CopyWithHierarchy() at line "DirectoryEntry de =
source.CopyTo(par);" with

"An unhandled exception of type
'System.Runtime.InteropServices.COMException' occurred in
system.directoryservices.dll

Additional information: Exception from HRESULT: 0x80005000."


Stack trace follows:
[ said:
migratewebservices.dll!MigrateWebServices.WSMigration.CopyWithHierarchy(System.DirectoryServices.DirectoryEntry source = {System.DirectoryServices.DirectoryEntry}) Line 74 + 0xd bytes C#

migratewebservices.dll!MigrateWebServices.WSMigration.CopyWithHierarchy(System.DirectoryServices.DirectoryEntry
source = {System.DirectoryServices.DirectoryEntry}) Line 80 + 0x21
bytes C#

migratewebservices.dll!MigrateWebServices.WSMigration.CopyWithHierarchy(System.DirectoryServices.DirectoryEntry
source = {System.DirectoryServices.DirectoryEntry}) Line 80 + 0x21
bytes C#

migratewebservices.dll!MigrateWebServices.WSMigration.SearchRelatedSettings(System.DirectoryServices.DirectoryEntry
ent = {System.DirectoryServices.DirectoryEntry}) Line 57 C#

migratewebservices.dll!MigrateWebServices.WSMigration.SearchRelatedSettings(System.DirectoryServices.DirectoryEntry
ent = {System.DirectoryServices.DirectoryEntry}) Line 41 + 0xec
bytes C#

migratewebservices.dll!MigrateWebServices.WSMigration.SearchRelatedSettings(System.DirectoryServices.DirectoryEntry
ent = {System.DirectoryServices.DirectoryEntry}) Line 41 + 0xec
bytes C#

migratewebservices.dll!MigrateWebServices.WSMigration.SearchRelatedSettings(System.DirectoryServices.DirectoryEntry
ent = {System.DirectoryServices.DirectoryEntry}) Line 41 + 0xec
bytes C#

migratewebservices.dll!MigrateWebServices.WSMigration.MigrateSettings()
Line 36 C#
TestApp.exe!TestApp.Class1.Main(string[] args = {Length=0}) Line
28 C#
 
So no ideas? I have to finish this project today, because we are having
a major serving migration tomorow, and witout this software it will be
much more work....
 
| So no ideas? I have to finish this project today, because we are having
| a major serving migration tomorow, and witout this software it will be
| much more work....
|

Are you trying to copy DirectoryEntry objects from one metabase to another,
that is on different servers? That's not possible with CopyTo, both entries
must reside within the same directory (metabase) as CopyTo acts on a single
connection.

What you need to do is re-create the same object hierarchy at the
destination, so you'll have to retrieve the objects and properties from the
source and re-create them on the dest.

Willy.
 
Back
Top