ASP.Net cannot see shared folder
I wrote a new app on a network that didn't work before and I have a problem.
If I have the following C # code:
FileStream fs = File.Create(@"\\MyServer\MyShare\testing.txt");
fs.Close();
In a console application, this code runs correctly.
In ASP.Net application, I get this error: Login failed: unknown username or incorrect password.
In an ASP.Net application, if I add the id impersonate = "true", I get this error: Access to path '\ MyServer \ MyShare \ testing.txt' is denied.
I have never encountered this login error message; where does it come from? If I create an app on the server and write it in a phsyical location it works fine (so the security is good there), it looks like the security for this resource is not working (although it has a "Everyone" set to the full entry), or something- something is missing at the server level where I am not allowed to view anything at all at all.
Does anyone know what I'm missing here? I've written other apps that did similar things and never faced this problem.
Thank!
source to share
Update:
So, I think I posted this too soon ... The reason it didn't execute on my localhost was because the directory was set to be allowed anonymous access (so the page didn't pretend to be an image and the user was ").
It also started working on the server; however, nothing was changed there ... I don't know if something was started during app idle / shutdown or what, but everything works as expected.
Thanks for the comments!
source to share
The problem is that with impersonation set to false, the ASP.NET worker process account tries to write to the share, usually the NETWORK SERVICE or ASPNET account. Depending on the version of windows used.
impersonating true, without specifying a username or password, the current user authentication will be used to try to make the request.
You either need to grant permission to the workflow account, which is most likely not possible. Or B create a specific account that your application can impersonate and then specify the credentials inside web.config in the identity tag.
source to share
By default, ASP.NET applications run as YourMachine \ IUSR_YourMachine. You either need to open share permissions for the Everyone principal (which might still not work if the machines are not in the same domain), or you run your IIS application as someone who has access to that share.
You can change the user that the ASP.NET application is running to:
Open Administration → Internet Information Services , then right-click the website or virtual directory containing the application and click Properties . Select the Directory Security tab and click Edit . Finally, in the Anonymous Access section, enter the username and password of the user who has access to the share.
Mike
source to share