Click here to Skip to main content
16,016,613 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
The following code works only for local system but i need to be work in remote/another system also.. While execute with remote system error come like this: Access is Denied. And also Give solution to acces privileges of access another system.

Thanks,
Sankar.



public DirectoryEntry Connect()
{
DirectoryEntry iisServer = null;
try
{
if (txtDirPath.Text.ToLower().Trim() == "localhost")
iisServer = new DirectoryEntry("IIS://" + txtDirPath.Text.Trim() + "/W3SVC/1/Root");

else
{
//Server name:-- txtDirPath.Text="servername/another systemname"
iisServer = new DirectoryEntry("IIS://" + txtDirPath.Text.Trim() + "/W3SVC/1/Root", "abc", "xyz");
}
}
catch (Exception e)
{
throw new Exception("Could not connect to: " + txtDirPath.Text.Trim(), e);
}
return iisServer;
}
public static string VirDirSchemaName = "IIsWebVirtualDir";
private void button1_Click(object sender, RoutedEventArgs e)
{
try
{
CreateVirtualDirectory(Connect());
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void CreateVirtualDirectory(DirectoryEntry iisServer)
{
try
{
DirectoryEntry newVirDir = iisServer.Children.Add(txtName.Text.Trim(), VirDirSchemaName);
newVirDir.CommitChanges();
newVirDir.Properties["AccessRead"].Add(true);
newVirDir.Properties["Path"].Add(txtDirPath.Text);
//newVirDir.Properties["Path"].Add(@"\\servername(OR) anothersystemname");
newVirDir.Invoke("AppCreate", true);
newVirDir.CommitChanges();
iisServer.CommitChanges();
newVirDir.Close();
iisServer.Close();
MessageBox.Show("Virtual Directory is Creatd!");
}
catch (Exception e)
{
throw new Exception(e.Message);
}

}
Posted

Access denied means what it says. You may or may not be able to gain this access, but you'll gain it in the settings on the machine, not through changing your code.
 
Share this answer
 
Please don't push 'answer' if you're asking more questions, edit your post.

Read the error messages, or look at the permissions you can set within IIS. You need permission in ISS, and permission to create the actual folder in the foreign file system
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900