No write access to file system

Discussion in 'General troubleshooting' started by troyhunt, Dec 29, 2010.

  1. I'm having some problems I hope someone can shed some light on. Contrary to the Winhost message of "By default the asp.net user has full permissions to your site", I simply cannot get the following code to execute on my site:

    var dir = Server.MapPath("~/MyFolder/NewPath");
    Directory.CreateDirectory(dir);

    This always returns an UnauthorizedAccessException and any other attempt to write to the file system (i.e. creating a text file), results in an error. I've just tried creating a brand new empty ASP.NET web app with all the defaults and the same thing happens.

    Personally, I believe the identity the app is running under simply doesn't have write access to the file system. Winhost have now said it's an app configuration error and that I should seek support from the programming community. There's a question on Stack Overflow under Possible causes for Directory.CreateDirectory throwing UnauthorizedAccessException on shared host.

    Would anyone here have any thoughts on possible causes? Likewise, can anyone here actually write files or directories to their Winhost site?
     
    Last edited by a moderator: Oct 14, 2015
  2. Ray

    Ray

    Whats is the full error message? Do you have a URL we can look at and see the error message?
     
  3. Hi Ray, give this a go: http://coles.troyhunt.com

    Entire codebase as follows:

    using System;
    using System.IO;
    using System.Web.UI;

    namespace Web
    {
    public partial class Default : Page
    {
    protected void Page_Load(object sender, EventArgs e)
    {
    var directoryName = DateTime.Now.ToString("yymmddhhmmss");
    var directoryPath = Server.MapPath(directoryName);
    Directory.CreateDirectory(directoryPath);
    DirectoryLabel.Text = directoryName;
    }
    }
    }

    Tested and running fine in a development environment where the identity running the app pool has write permissions to the path.
     
  4. Ray

    Ray

    How did you publish this app? Did you use web deploy? If you did open a ticket to our support department. Tell them you lost some rights to your root because of web deploy. This is a known issue with Microsoft's web deploy and we have contacted them of this issue. Our support department will have to reset your permission. If you already have a ticket for this issue, simply reply back to the ticket and the ticket system will reactivate the ticket. But make sure you tell them that you used web deploy to published the site.
     
  5. Web deploy

    Ah, very interesting. Yes, I did use web deploy. Responding to the ticket right now...
     
  6. Well, that fixed it. Permissions were reset by Winhost and I'm now strictly publishing via FTP.

    Of course this begs the question, why offer web deploy if there are known issues with it in Winhost's configuration? Perhaps something to advise customers of, I blew a lot of time trying to resolve this.
     
    Last edited by a moderator: Oct 14, 2015
  7. I'll have to wait for the support rep that answered your support ticket, but I'm pretty sure it's because Web Deploy changes the ACLs on files/folders, basically making them read only or changing it to whatever it wants. There are ways around this though, but probably the easiest is to just use FTP.
     
  8. Ray

    Ray

    Yeah web deploy modifies the ACL for the ASPNet IUSR account. This is the default setting in VS when doing web deploy. We contacted Microsoft about this and let them know. Not sure if they will deploy a fix to this or if in the next version of VS this will be resolved.
     

Share This Page