Originally Posted by
codecarnage
Ok Guys, I have a slightly big problem...I have web application running on IIS which is now required to write files to a mapped directory. I'm receiving what appears to be a permissions error...
Has anyone suggessfully accomplished this using CLASSIC ASP?
I do know that setting privileges to "everyone" on the mapped directory won't work because "everyone" context is restricted to the local machine.
Any information you can share will be greatly appreciated.
It has nothing to do with permission s, you have to map the drive into the process using the appropraite credentials (username, password). Here is a C# sample from one of my projects to do that. Not sure if you are a C# person but hope this helps.
Code:
/// <summary>
/// Maps a network drive as a local drive to the calling process.
/// </summary>
public bool WNetAddConnection(string LocalDrive, string NetworkFolderPath, string User, string Password, bool Force)
{
bool success = false;
try
{
NetResource netresource = new NetResource();
netresource.Scope = RESOURCE_GLOBALNET;
netresource.Type = RESOURCETYPE_DISK;
netresource.Usage = RESOURCEUSAGE_CONNECTABLE;
netresource.DisplayType = RESOURCEDISPLAYTYPE_SHARE;
netresource.LocalName = LocalDrive;
netresource.RemoteName = NetworkFolderPath;
netresource.Comment = "";
netresource.Provider = "";
int Flag = CONNECT_UPDATE_PROFILE;
if(Force)
{
success = WNetCancelConnection(LocalDrive, true);
}
int result = WNetAddConnection2A(ref netresource, Password, User, Flag);
if(result > 0)
{
throw new System.ComponentModel.Win32Exception(result);
}
success = true;
}
catch(Exception ex) { Logger.Error(ex.Message); }
return success;
}
/// <summary>
/// UnMaps a network drive from the calling process.
/// </summary>
public bool WNetCancelConnection(string LocalDrive, bool Force)
{
bool success = false;
try
{
int result = WNetCancelConnection2(LocalDrive, CONNECT_UPDATE_PROFILE, Force);
if(result > 0)
{
throw new System.ComponentModel.Win32Exception(result);
}
success = true;
}
catch(Exception ex) { Logger.Error(ex.Message); }
return success;
}
There are some other classes that are needed but you get rthe idea.