Thursday, February 24, 2011

System.UnauthorizedAccessException: Access to the path is denied

During my recent deployment to a QA box, one of the functionalities "Upload File" of the web app would not work.

Here is what I had done. During development I observed that the file upload would work when I was running the app in Debug mode, from within Visual Studio. When I tried running the app from virtual directory (as in http://localhost/MyApp/Upload.aspx) the file upload would fail with "Logon failure: unknown user name or bad password", about which I blogged a while ago. And hence I added the code to impersonate the current logged in user. And it worked fine.

However, the same impersonation code would not work when the app was deployed on the server. Another thing I should point out is, the file copy is happening on a server different from the app server. When I commented out the impersonation code, it started working. I am still not sure why it so happened.


No comments: