0
Answer

Problem while writing to Remote Location in a .Net Thread

vishal sharma

vishal sharma

17y
1.6k
1

hi

i am having problem when i am trying to write something on remote location using .net thread.
e.g. i have a central location letsay MachineName|MachineIP/SharedDrive.
and i am creating a thread on click of a button which i need to write some information on that location.

i have also added a node  <identity impersonate="true" userName="Domain\User" password="*******"/> in web.config of my application.

and i have also given credential in <Machine.Config>--<ProcessModel enable="true" UserName="SameInWeb.Config" password="SameInWeb.Config">

but it is giving the following exception:
The system detected a possible attempt to compromise security. Please ensure that you can contact the server that authenticated you.

below is my method which i am calling on a separate thread.
private void WriteSomeThingToRemoteLocation ()

        {
            FileStream fileStream = null;
            BinaryFormatter binaryFormatter = null;
            System.Object systemObject = null;
            System.Object obj = new object();
            lock ( obj )
            {
                string _contractLocaterKey = Guid.NewGuid().ToString().Replace( "-", "" );

                string fullPath = @"\\MyMachineIP\SharedDrive" + "\\" + _contractLocaterKey + ".dat";
                    try
                    {
      fileStream = new FileStream( fullPath, FileMode.CreateNew, FileAccess.Write );
                        binaryFormatter = new BinaryFormatter();

                        systemObject = new object();
                        systemObject = "Hello this is testing1";
                        binaryFormatter.Serialize( fileStream, systemObject );

                        systemObject = new object();
                        systemObject = "Hello this is testing2";
                        binaryFormatter.Serialize( fileStream, systemObject );
                }
//    catch(Exception ex)
//    {
//     avoided for getting noticed what happened;
//    }
                finally
                {
                    if ( fileStream != null )
                    {
                        fileStream.Close();
                        fileStream = null;
                    }
                    binaryFormatter = null;
                    systemObject = null;
                }
            }
        }

please help in this matter as i am stucking in the problem from more than 3 days.

this thing is happening  OK :
1. if i call this method directly on another method.
2. if i call this method in a console application .
3. if i call this method on a thread in a console application.

any help would be highly appreciated.

thanks

vishal sharma