Read file not working after deploying to IIS 7

Last post 07-03-2009 5:36 AM by Thomas Sun – MSFT. 4 replies.

Sort Posts:

  • Read file not working after deploying to IIS 7

    06-29-2009, 2:54 PM
    • Member
      3 point Member
    • bagustri
    • Member since 06-27-2009, 10:34 AM
    • Posts 14

    Hi All,

    I am building a simple file-driven CMS application.  
    The pieces that make up a final page are stored as regular html files, and are stored in a fixed folder structure.
    Each file that is required by a final page is read from said folders and placed into the template file (which is also read from file).

    Everything works as it should when running from VS/localhost.  However, as soon as I deploy it to my local IIS and access the site via IP, it breaks on the very first instance of a file read.

    I have read that this is due to some security/permission issue, which doesn't allow files to be read/written to under certain conditions.

    I can't say I fully understand the issue, therefore I seek your kind help in enlightening me, if there is a way for me to get around this issue?  
    The CMS is built, and is running well.  On localhost.  Now that it is on a proper server, the most basic functionality (reading files) is broken.

    Any help will me much appreciated.  Thank you beforehand.

  • Re: Read file not working after deploying to IIS 7

    06-29-2009, 3:58 PM
    Answer
    • All-Star
      75,795 point All-Star
    • jeff@zina.com
    • Member since 09-26-2003, 10:43 AM
    • Naples, FL, USA
    • Posts 10,314
    • Moderator
      TrustedFriends-MVPs

    bagustri:
    The CMS is built, and is running well.  On localhost.

    And, I assume, in the Visual Studio environment.  IIS runs under the ASP.NET process account.  Visual Studio runs under the logged in user.  Change the file/folder permissions to allow the correct account access.

    Jeff

    Blatant Self Promotion: ASP.NET 3.5 CMS Development
  • Re: Read file not working after deploying to IIS 7

    06-29-2009, 4:44 PM
    Answer

    Hello,

    Jeff is right and you should give a write permission of ASP.NET account.

    Regards

  • Re: Read file not working after deploying to IIS 7

    06-29-2009, 9:52 PM
    • Member
      3 point Member
    • bagustri
    • Member since 06-27-2009, 10:34 AM
    • Posts 14

    @Jeff & Hosting

    Thanks for clearing that up, but might I ask what account name I should be giving permission to?  I can't seem to find any account names with ASP or ASP.NET in it.

    If I were to guess, I would guess the IIS_IUSRS account.  Would that be correct?  The server admin is on leave so there's nobody around to advise me on this.

    FYI, the server is running Windows Server 2008.

    Edit:

    I had not modified any permissions yet, but I've been tampering with my paths and found something odd.

    I've been using Path.GetFullPath() to get to my Content folder.  
    If I comment this line and replace it with a hard-coded path (F:\\Path\\To\\Content) everything works.  But this would of course be bad practice. Interestingly, one would assume that Path.GetFullPath() would give the correct path as the name implies, though this didn't seem to be the case for me.

    Curious, I looked around and found out about the System.AppDomain.CurrentDomain.BaseDirectory property.  Tried it, and it also works fine.  Would this be an acceptable solution in my case?


  • Re: Read file not working after deploying to IIS 7

    07-03-2009, 5:36 AM
    Answer

    Hi,

    Where is the file that you are trying to access from your project? Please make sure the file path is correct and your application process identity has permission on that file.

    Since your application is running under IIS, ASP.NET process identity is "ASPNET" or "NETWORK SERVICE" depending on IIS version by default. In your case, it should be "NETWORK SERVICE".

    In your case, please make sure we grant proper permissions to the account on the file. You can follow this article (http://www.asp.net/learn/whitepapers/denied-access-to-iis-directories/) to implement it.

    For testing, we can try to grant proper permissions to "EVERYONE" on that file to see if it works.

    If the file is within your application directory, I suggest you use Server.MapPath Method (http://msdn.microsoft.com/en-us/library/system.web.httpserverutility.mappath.aspx) to get its path.
     
    I look forward to hearing from you.

    Thomas Sun
    Microsoft Online Community Support

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question.
Page 1 of 1 (5 items)