Access to path denied on IIS

*爱你&永不变心* 提交于 2019-12-02 08:25:24

You need to check whether other processes already have the file open, e.g, "A separate process is looking in that folder for text files to grab" - perhaps this separate process already has the file open and is therefore locking out your IIS process? Use Process Monitor (https://docs.microsoft.com/en-us/sysinternals/downloads/procmon) to monitor activity on the file.

Also you give the file location as '\server\C$\folder\subfolder\file.txt'. UNC paths normally begin with a '\\', e.g., '\\server\C$\folder\subfolder\file.txt'. That may just be an artefact of StackOverflow escaping the double slash to a single slash.

As a simple test, can you use notepad with your own account to open the file in the error message and write to the file? What if you use the application pool identity account?

Edit: You run Process Monitor on the server that has the file location. Add a Path filter like this:

Path   excludes    file.txt   then  Exclude

Where file.txt is the file name (without the directory) of the file you are monitoring. This filter will only capture events for that file and will exclude everything else. Once an event occurs, right click it, and go to Properties, Process to see the User initiating the event.

First of all, you can try to give write rights to IUSR user on your folder in which you want to write your text file.

There is a way to imitate an user in your asp.net application by using Impersonate tag in your web.config file but I think this can be dangerous.

  <identity impersonate="true" userName="nomducompte" password="motdepasse" />

I hope this helps.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!