Ver Mensaje Individual
  #1 (permalink)  
Antiguo 29/07/2008, 16:30
mib519
 
Fecha de Ingreso: julio-2008
Mensajes: 1
Antigüedad: 16 años, 8 meses
Puntos: 0
IIS crear desde codigo una carpeta virtual

Saludos.. no soy muy fan de solicitar ayuda... pero ahora si que me fallo la logica.
resulta que creo mi directorio virtual en mi maquina y este se crea correctamente
pero al pasarlo a un servidor me arroja errores y pues ya esytoy medio frustrado
les dejo la clase y el error que manda..

public void CreateVDir(string metabasePath, string vDirName, string physicalPath)
{
metabasePath = metabasePath + ConfigurationSettings.AppSettings.Get("idVirtualDi rectory");
try
{
DirectoryEntry site = new DirectoryEntry(metabasePath);
string className = site.SchemaClassName.ToString();
if ((className.EndsWith("Server")) || (className.EndsWith("VirtualDir")))
{
DirectoryEntries vdirs = site.Children;
DirectoryEntry newVDir = vdirs.Add(vDirName, (className.Replace("Service", "VirtualDir")));
// newVDir.Children.Add(vDirName, "IIsWebVirtualDir");
/*Propiedades*/
newVDir.Properties["Path"][0] = physicalPath;
newVDir.Properties["AccessScript"][0] = true;
newVDir.Properties["AppFriendlyName"][0] = vDirName;
newVDir.Properties["AppIsolated"][0] = "1";
newVDir.Properties["AppRoot"][0] = "/LM" + metabasePath.Substring(metabasePath.IndexOf("/", ("IIS://".Length)));
newVDir.Properties["AccessRead"][0]= true;
newVDir.Properties["AccessExecute"][0] = true;
newVDir.Properties["AccessWrite"][0]= false;
newVDir.Properties["AccessScript"][0] = true;
newVDir.Properties["AuthNTLM"][0] = true;
newVDir.Properties["EnableDefaultDoc"][0] = true;
newVDir.Properties["DefaultDoc"][0] = "default.htm,default.aspx,default.asp";
newVDir.Properties["AspEnableParentPaths"][0] = true;
/*Esta es la linea 222 falla al querer darle Commit no tengo permiso para eso*/
newVDir.CommitChanges();
newVDir.Invoke("AppCreate",1);
//Console.WriteLine(" Done.");
Response.Write("<script>alert('Listo');</script>");

}
else

Response.Write("<script>alert('Failed. A virtual directory can only be created in a site or virtual directory node.');</script>");
Console.WriteLine(" Failed. A virtual directory can only be created in a site or virtual directory node.");
}
catch (Exception ex)
{
Response.Write(ex.ToString());
//Response.Write("<script>alert('Failed in CreateVDir with the following exception:" + ex.Message+ "');</script>");
Console.WriteLine("Failed in CreateVDir with the following exception: \n{0}", ex.Message);
}
}
System.UnauthorizedAccessException: Access is denied.
(Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
at System.DirectoryServices.Interop.UnsafeNativeMetho ds.IAds.SetInfo()
at System.DirectoryServices.DirectoryEntry.CommitChan ges()
at ManagerPaginasWeb.AdminPaginasWeb.NuevoSite.Create VDir(String metabasePath, String vDirName, String physicalPath)
in c:\ManagerPaginasWeb\AdminPaginasWeb\NuevoSite.asp x.cs:line 222