问题描述
以下代码仅适用于本地系统,但我也需要在远程/另一个系统中工作..在执行远程系统错误时出现如下错误:访问被拒绝.并提供解决方案以访问其他系统的acces特权.
谢谢,
桑卡尔.
公共DirectoryEntry Connect()
{
DirectoryEntry iisServer = null;
试试
{
如果(txtDirPath.Text.ToLower().Trim()=="localhost")
iisServer = new DirectoryEntry("IIS://" + txtDirPath.Text.Trim()+"/W3SVC/1/Root");
其他
{
//服务器名称:-txtDirPath.Text =服务器名称/另一个系统名称"
iisServer = new DirectoryEntry("IIS://" + txtDirPath.Text.Trim()+"/W3SVC/1/Root","abc","xyz");
}
}
catch(异常e)
{
抛出新的Exception(无法连接到:" + txtDirPath.Text.Trim(),e);
}
返回iisServer;
}
公共静态字符串VirDirSchemaName ="IIsWebVirtualDir";
private void button1_Click(对象发送者,RoutedEventArgs e)
{
试试
{
CreateVirtualDirectory(Connect());
}
catch(ex ex例外)
{
MessageBox.Show(ex.Message);
}
}
私有无效CreateVirtualDirectory(DirectoryEntry iisServer)
{
试试
{
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(虚拟目录已创建!");
}
catch(异常e)
{
抛出新的Exception(e.Message);
}
}
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);
}
}
推荐答案
这篇关于在in-in和另一个系统上创建虚拟目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!