I'm ashamed it took me 3 days to figure this out. I have a web app that performs a file operation using System.IO.FileStream. It worked fine on my local dev box, but as soon as I pushed it to my GoDaddy server, I got a System.UnauthorizedAccessException error "Access to the path xxx is denied." Here's how I fixed it.
As always, I'm quick to state this is probably not the best way, but it worked for me, and after 3 days of fighting with it, I don't care as long as it works.
I created a little temporary test page like this:
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Security.Principal" %>
<%@ Import Namespace="System" %>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
WindowsIdentity identity = WindowsIdentity.GetCurrent();
Response.Write("Windows user name: " + identity.Name + "<br>");
}
</script>
I uploaded this to my server and viewed it in a web browser. I copied the name that was displayed on the page verbatim. I logged into my server (Windows Server 2003) and navigated to the folder that my code was trying to access. I right-clicked the folder, chose properties, and the security tab.
I clicked on "Add", and in the "Enter the object names to select" field, I pasted the name that I copied from my test web page. I went with the permissions that were given by default, but I suppose you could twique that to your needs.
After I did this, my app worked on my server. Yay!
Here are some links that gave me some clues to solving this:
http://support.microsoft.com/kb/306158
http://www.dotnetmonster.com/Uwe/Forum.aspx/asp-net/53726/Access-to-the-path-is-denied-trying-to-write-a-file
http://www.velocityreviews.com/forums/t115604-access-to-the-path-is-denied-trying-to-write-a-file.html
By the way, I'm equally ashamed that it has taken me a year to write another blog entry. I'll try to better going forward. I've definitely learned a lot over the last year that I would like to put on here for my own reminders if nothing else.
On another note, I've moved from the vastly simpler world of GoDaddy shared hosting to a GoDaddy virtual server. It has been a painful transition. This little article is just one of the many lessons I had to learn.