System.IO.Ioexception: The user name or password is incorrect

Asked

Viewed 736 times

0

I built an application using Asp.net where in a few moments of the application I need to access a directory and scan files and sometimes move and delete them. On my micro worked perfectly, but when climbing the application on the IIS server it started to return the error System.IO.Ioexception: The user name or password is incorrect.. I accessed the server and logged in the directory I need to access, besides that I gave permission to the IUSR user (by the way for all), to access, but I keep receiving the error message. Is there any way to log into the application in the directory passing user and password or be able to access the directory in some other way?

Note: The micro I am trying to access is not in the same domain as my server and unfortunately I cannot put them in the same domain.

  • Let me get this straight, you have an application on the x server that tries to access a directory on the y server. That’s it?

  • Yes. One server sees the other, only inside the application is not working.

  • Dude, how are connecting or other micro? ftp? Show me the code!

  • Apparently, you are trying to access a folder from a server that requires logon. When starting the service on IIS, it attempts to access with the IUSR credential, which will not be validated on the other server. I found something that seems to solve: I don’t know if it will work for Asp.net https://stackoverflow.com/questions/5023607/how-to-use-logonuser-properly-to-impersonate-domain-user-from-workgroup-client

  • Locally I didn’t need to log in using the application. I logged in windows itself. In my application I am basically running Directory.GetFiles(); and works normally. Already on the server does not roll. At first I thought it might be something in windows. But what I did locally did not roll on the server.

  • @Rovannlinhalis I will try to implement this code and put the result.

  • you can also use a mapped network drive. Have you tried ? can be easier

  • I tried using the mapped drive, again locally worked perfectly. Already on the server did not roll. Just call me back and tell me that the path has not been found.

  • uses command prompt as administrator to map the unit

  • Enter the code of how you are doing to access this directory

  • At first I managed to do it with a "gambiarra". I created a user on my application server and another on the target server with the same username and password. So the system was able to access and manipulate the files.

Show 6 more comments

2 answers

1

Goodnight,

Try the following piece of code:

using (var networkCon = new NetworkConnection(destinationFolder, New NetworkCredential(username, password))
{
    File.ReadAllText(destinationFolder + "Teste.txt");
}

0

This happens because the username in which the app is running on the production machine does not have access on the other server, giving Exception.

Probably ran locally because the user running the local machine has access to this remote server, not giving error.

  • The security of the folder I’m trying to access is set to all.

  • Have you seen the Application pool Identity ?

  • Yes, I switched to a user with more privileges and still didn’t roll.

  • put permission in the directory like this guy does in this tutorial? https://docs.litium.com/more/best-practices/tips-tricks/give-directory-access-permission-to-iis-application-pool

  • tb test <Identity impersonate="true" /> on your webconfig

  • Even if the folder security on the other server is as permission for All, the server requires authentication when trying to access the shared folders. Then the problem happens.

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.