PDA

View Full Version : راه حلی برا ی خطای Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))



Mostafa_Sabeti
یک شنبه 06 اسفند 1391, 20:34 عصر
سلام من برای ساختن Virtual Directory یک کد دارم بصورت زیر:


public void CreateVirtualDir(string WebSite, string AppName, string Path)
{
System.DirectoryServices.DirectoryEntry IISSchema = new System.DirectoryServices.DirectoryEntry("IIS://" + WebSite + "/Schema/AppIsolated");
bool CanCreate = IISSchema.Properties["Syntax"].Value.ToString().ToUpper() != "BOOLEAN";
IISSchema.Dispose();
if (CanCreate)
{
bool PathCreated = false;
try
{
System.DirectoryServices.DirectoryEntry IISAdmin = new System.DirectoryServices.DirectoryEntry("IIS://" + WebSite + "/W3SVC/1/Root");
if ( !System.IO.Directory.Exists(Path)) {
System.IO.Directory.CreateDirectory(Path);
PathCreated = true;
}
foreach (System.DirectoryServices.DirectoryEntry VD in IISAdmin.Children)
{
if (VD.Name == AppName) {
IISAdmin.Invoke("Delete", new String[] {VD.SchemaClassName, AppName});
IISAdmin.CommitChanges();
break;
}
}
System.DirectoryServices.DirectoryEntry VDir = IISAdmin.Children.Add(AppName, "IIsWebVirtualDir");
VDir.Properties["Path"][0] = Path;
VDir.Properties["AppFriendlyName"][0] = AppName;
VDir.Properties["EnableDirBrowsing"][0] = false;
VDir.Properties["AccessRead"][0] = true;
VDir.Properties["AccessExecute"][0] = true;
VDir.Properties["AccessWrite"][0] = false;
VDir.Properties["AccessScript"][0] = true;
VDir.Properties["AuthNTLM"][0] = true;
VDir.Properties["EnableDefaultDoc"][0] = true;
VDir.Properties["DefaultDoc"][0] = "default.htm,default.aspx,default.asp";
VDir.Properties["AspEnableParentPaths"][0] = true;
VDir.CommitChanges();
//the following are acceptable params
//INPROC = 0
//OUTPROC = 1
//POOLED = 2
VDir.Invoke("AppCreate", 1);
}
catch (Exception ex)
{
if (PathCreated) {
System.IO.Directory.Delete(Path);
}
throw ex;
}
}
}


اما با اجرا ی آن خطای Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)) صادر میشود. در IIS5 کجا باید چه دسترسی ای را true کرد؟