Enabling File Permissions For Your ASP.NET App on Windows Server 2003

by Marvin 15. March 2010 03:18

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. 

Currently rated 3.0 by 1 people

  • Currently 3/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

Comments

Add comment


(Will show your Gravatar icon)  

  Country flag

biuquote
  • Comment
  • Preview
Loading



About the author

I am a junior-level C# .NET developer living in Nashville, TN.  I'm currently working in biomedical informatics, developing a web service, a MySql database, and a web application.  Every week or so, I spend hours trying to figure out how to do something, and after I find the solution, I really want to make sure I don't go through that exercise again.  I love to write.  It helps me to remember things.  So, I use this blog as a way to document those painful lessons as I learn them.  It has already helped me to be able to refer back to them.  I hope some of these will save someone else some time as well.