简体   繁体   中英

asp.net create folder and file in other server

In my asp.net application I have an option to take photographs, these photographs should not store the hosting server, the photographs should be stored on another server. (\\192.168.1.103\\ca\\photos\\ I use this code

public void EstructuraReclamo(string Producto, string Poliza, string Sucursal,string Reclamo, string Item) {
string Mensaje = string.Empty;
string DirServidor = DireccionIP(ref Mensaje, "SCANDATOS", Sucursal, "RECLAMOS");           
try
{
    string DirReclamo =DirServidor + Producto + @"\" + Poliza + @"\Item" + Item + @"\" + Reclamo;
    if (!System.IO.Directory.Exists(DirReclamo)){
        System.IO.Directory.CreateDirectory(DirReclamo);
    }
    System.Data.DataTable dtSubdirectorios = ListaSubDirectorio(ref Mensaje, "SCANRECLAMO");
    foreach (System.Data.DataRow dr in dtSubdirectorios.Rows) { 
        string SubDir = DirReclamo + @"\" + dr["apa_glosa"].ToString();
        if (!System.IO.Directory.Exists(SubDir))
            System.IO.Directory.CreateDirectory(SubDir);
    }

}
catch (Exception ex){
    Mensaje = ex.Message.ToString();
}

But the folders are not created? When I execute the program from VS2010 the folders are created, but when publish the site the folders are no created How I can solve this problem?

The version IIS is 6.0

Though I don't know whether or not you're getting an exception at the moment, this is almost assuredly a permissions issue. IIS is going to send the credentials the Application Pool is running under when trying to create the folders. This is generally defaulted to NETWORK SERVICE .

Have a look at the user the Application Pool is running under, then check out the permissions of the root folder, and ensure that user has Write access.

Once the Application Pool user has permissions -you're good.

This will be a permissions issue, when you run the program using visual studio the application runs with your own credentials, however when the site is run in IIS it will run with whichever account is assigned to the application pool and by default this will be a local account on the machine which won't have any permissions on a remote server.

If you use impersonation you can setup an account which has the relevant permissions on the remote server and your application will have access to those remote folders/files.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM