I am trying to connect to a network location through my ASP.NET web application using WNetAddConnection2. Every thing works perfectly when I debug it using the ASP.NET Development Server provided along with VS2010. But when I deploy the code in a Windows Server 2008 R2 it does not place the file and throws a Win32 exception with error code 0X80004005. The application pool identity is network service and i am using a domain user account for imparsanation.

I have checked the connectivity and user name password validity using the command and it works pefectly from the server runas /netonly /user:DOMAIN\User "explorer.exe \Path"

Please also note my firewall is switched off and i dont have an antivirus running on the Windows Server 2008.

Any help is really appreciated.

I have used the sample code from [How to provide user name and password when connecting to a network share](https://stackoverflow.com/questions/295538/how-to-provide-user-name-and-password-when-connecting-to-a-network-share)