Copy file problem !!

  • Thread starter Thread starter Paul
  • Start date Start date
P

Paul

Dear All,


I want to use web form to upload my file and copy the file to another
machine.
I can upload the file, but when I copy the file(file.CopyTo(".....", true))
to another machine(map network driver), it failed(error message : login
failed......).
So.... how should I do if I want the upload file can copy to another
machine. Thanks !!
 
I want to use web form to upload my file and copy the file to another
machine.
I can upload the file, but when I copy the file(file.CopyTo(".....", true))
to another machine(map network driver), it failed(error message : login
failed......).
So.... how should I do if I want the upload file can copy to another
machine. Thanks !!


I do not know anything about webforms but I do know about .NET security.
Standard .NET security defaults not to accept any network connection.
So "file open" on a network drive will fail while on the local drive it will
succeede.
You have to tell the program that he must have access to the network too.

In C# you have an assembly.cs file and I added these (just copied and
pasted, I think that "ZoneIdentityPermission" and maybe "FileIOPermission"
would be enough)
----------------
using System;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using System.Runtime.InteropServices;

[assembly:SecurityPermission(SecurityAction.RequestMinimum,
UnmanagedCode=true)] // Request to run unmanaged code
[assembly:FileIOPermission(SecurityAction.RequestMinimum,
Unrestricted=true)] // Request complete File IO functionality
[assembly:RegistryPermission(SecurityAction.RequestMinimum, All="*")] //
Request complet access to the registery key
[assembly:ZoneIdentityPermission(SecurityAction.RequestMinimum,Zone=Security
Zone.NoZone)] // Request unrestricted zone
-------------------
 
You web application doesn't have the necessary privileges to access the
remote share.
Here are a number of options to solve this:

1) You can run your web application using alternate credentials by changing
the machine.config file
<Process ....model - userName, password
2) You can create a new logon session by calling Win32's LogonUser API and
impersonate (search the KB for samples).
3) You can impersonate the base client, but this requires a correctly
configured Kerberos realm and delegation.
Other options are using calling a COM+ server type application running with
fixed (valid) credentials for the file copy operation, or using remoting to
call the copy operation from a windows service running with fixed
credentials.

Willy.
 
Back
Top