ASP.NET doesn't have permission to access resource

Discussion in 'ASP .Net' started by Brent Bigler, Dec 17, 2003.

  1. Brent Bigler

    Brent Bigler Guest

    The computer: W2K server, domain controller, Microsoft.Net Framework 1.1

    ========================
    The error message:

    Access to the path "c:\fanmail\newfiles" is denied
    ....

    Exception Details: System.UnauthorizedAccessException: Access to the path
    "c:\fanmail\newfiles" is denied

    *(see below for Stack Trace)

    ========================

    Fixes tried (but didn't work):

    1. Added ASPNET account to c:\fanmail\newfiles and granted full permission
    to resource;

    2. Added ASPNET to Administrator group;

    3. Changed machine.config processModel username setting to "SYSTEM";

    4. Changed machine.config processModel username setting to "{Domain}\ASPNET"
    along with the password setting to the appropriate password;

    5. Sacrificed three chickens and a goat (in theory).

    =======================

    Most of the articles I've read say it's simply a permissions problem, like
    the error reports. But it doesn't seem that any kind of permission changing
    on the resource works. Anything else I should try?

    Thanks for any help!

    --Brent

    ----------------------------------------------------------------------------
    -
    The code class giving me the problems (from clsFTP, downloaded from
    someplace on the Web)

    ===================================
    Public Sub DownloadFile(ByVal sFileName As String, _
    ByVal sLocalFileName As String, _
    ByVal bResume As Boolean)
    Dim st As Stream
    Dim output As FileStream
    Dim cSocket As Socket
    Dim offset, npos As Long

    If (Not (m_bLoggedIn)) Then
    Login()
    End If

    SetBinaryMode(True)

    If (sLocalFileName.Equals("")) Then
    sLocalFileName = sFileName
    End If

    If (Not (File.Exists(sLocalFileName))) Then
    st = File.Create(sLocalFileName) '<----Error here, I presume
    st.Close()
    End If

    output = New FileStream(sLocalFileName, FileMode.Open)
    cSocket = CreateDataSocket()
    offset = 0

    If (bResume) Then
    offset = output.Length

    If (offset > 0) Then
    SendCommand("REST " & offset)
    If (m_iRetValue <> 350) Then
    'throw new IOException(reply.Substring(4));
    'Some servers may not support resuming.
    offset = 0
    End If
    End If

    If (offset > 0) Then
    npos = output.Seek(offset, SeekOrigin.Begin)
    End If
    End If

    SendCommand("RETR " & sFileName)

    If (Not (m_iRetValue = 150 Or m_iRetValue = 125)) Then
    MessageString = m_sReply
    Throw New IOException(m_sReply.Substring(4))
    End If

    Do While (True)
    m_aBuffer.Clear(m_aBuffer, 0, m_aBuffer.Length)
    m_iBytes = cSocket.Receive(m_aBuffer, m_aBuffer.Length, 0)
    output.Write(m_aBuffer, 0, m_iBytes)

    If (m_iBytes <= 0) Then
    Exit Do
    End If
    Loop

    output.Close()
    If (cSocket.Connected) Then
    cSocket.Close()
    End If

    ReadReply()
    If (Not (m_iRetValue = 226 Or m_iRetValue = 250)) Then
    MessageString = m_sReply
    Throw New IOException(m_sReply.Substring(4))
    End If

    End Sub
    ===========================

    Stack Trace:

    [UnauthorizedAccessException: Access to the path "c:\FanMail\NewFiles" is
    denied.]
    System.IO.__Error.WinIOError(Int32 errorCode, String str) +393
    System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access,
    FileShare share, Int32 bufferSize, Boolean useAsync, String msgPath, Boolean
    bFromProxy) +888
    System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access,
    FileShare share, Int32 bufferSize) +44
    clsFTP.DownloadFile(String sFileName, String sLocalFileName, Boolean
    bResume) +120
    clsFTP.DownloadFile(String sFileName, String sLocalFileName) +13
    ASP.test_aspx.Page_Load() in C:\ClientsWeb\test.aspx:20
    System.Web.Util.ArglessEventHandlerDelegateProxy.Callback(Object sender,
    EventArgs e) +10
    System.Web.UI.Control.OnLoad(EventArgs e) +67
    System.Web.UI.Control.LoadRecursive() +35
    System.Web.UI.Page.ProcessRequestMain() +731
     
    Brent Bigler, Dec 17, 2003
    #1
    1. Advertising

  2. Brent Bigler

    Morgan Guest

    Have you given the IUSR_<MachineName> account access to the folder? Had a
    similar issue not to long ago, seems that the ASPNet account isn't enough
    and wound up having to give access to the folder to the IUSR_<MachineName>
    account.

    "Brent Bigler" <> wrote in message
    news:...
    > The computer: W2K server, domain controller, Microsoft.Net Framework 1.1
    >
    > ========================
    > The error message:
    >
    > Access to the path "c:\fanmail\newfiles" is denied
    > ...
    >
    > Exception Details: System.UnauthorizedAccessException: Access to the path
    > "c:\fanmail\newfiles" is denied
    >
    > *(see below for Stack Trace)
    >
    > ========================
    >
    > Fixes tried (but didn't work):
    >
    > 1. Added ASPNET account to c:\fanmail\newfiles and granted full permission
    > to resource;
    >
    > 2. Added ASPNET to Administrator group;
    >
    > 3. Changed machine.config processModel username setting to "SYSTEM";
    >
    > 4. Changed machine.config processModel username setting to

    "{Domain}\ASPNET"
    > along with the password setting to the appropriate password;
    >
    > 5. Sacrificed three chickens and a goat (in theory).
    >
    > =======================
    >
    > Most of the articles I've read say it's simply a permissions problem, like
    > the error reports. But it doesn't seem that any kind of permission

    changing
    > on the resource works. Anything else I should try?
    >
    > Thanks for any help!
    >
    > --Brent
    >
    > --------------------------------------------------------------------------

    --
    > -
    > The code class giving me the problems (from clsFTP, downloaded from
    > someplace on the Web)
    >
    > ===================================
    > Public Sub DownloadFile(ByVal sFileName As String, _
    > ByVal sLocalFileName As String, _
    > ByVal bResume As Boolean)
    > Dim st As Stream
    > Dim output As FileStream
    > Dim cSocket As Socket
    > Dim offset, npos As Long
    >
    > If (Not (m_bLoggedIn)) Then
    > Login()
    > End If
    >
    > SetBinaryMode(True)
    >
    > If (sLocalFileName.Equals("")) Then
    > sLocalFileName = sFileName
    > End If
    >
    > If (Not (File.Exists(sLocalFileName))) Then
    > st = File.Create(sLocalFileName) '<----Error here, I presume
    > st.Close()
    > End If
    >
    > output = New FileStream(sLocalFileName, FileMode.Open)
    > cSocket = CreateDataSocket()
    > offset = 0
    >
    > If (bResume) Then
    > offset = output.Length
    >
    > If (offset > 0) Then
    > SendCommand("REST " & offset)
    > If (m_iRetValue <> 350) Then
    > 'throw new IOException(reply.Substring(4));
    > 'Some servers may not support resuming.
    > offset = 0
    > End If
    > End If
    >
    > If (offset > 0) Then
    > npos = output.Seek(offset, SeekOrigin.Begin)
    > End If
    > End If
    >
    > SendCommand("RETR " & sFileName)
    >
    > If (Not (m_iRetValue = 150 Or m_iRetValue = 125)) Then
    > MessageString = m_sReply
    > Throw New IOException(m_sReply.Substring(4))
    > End If
    >
    > Do While (True)
    > m_aBuffer.Clear(m_aBuffer, 0, m_aBuffer.Length)
    > m_iBytes = cSocket.Receive(m_aBuffer, m_aBuffer.Length, 0)
    > output.Write(m_aBuffer, 0, m_iBytes)
    >
    > If (m_iBytes <= 0) Then
    > Exit Do
    > End If
    > Loop
    >
    > output.Close()
    > If (cSocket.Connected) Then
    > cSocket.Close()
    > End If
    >
    > ReadReply()
    > If (Not (m_iRetValue = 226 Or m_iRetValue = 250)) Then
    > MessageString = m_sReply
    > Throw New IOException(m_sReply.Substring(4))
    > End If
    >
    > End Sub
    > ===========================
    >
    > Stack Trace:
    >
    > [UnauthorizedAccessException: Access to the path "c:\FanMail\NewFiles" is
    > denied.]
    > System.IO.__Error.WinIOError(Int32 errorCode, String str) +393
    > System.IO.FileStream..ctor(String path, FileMode mode, FileAccess

    access,
    > FileShare share, Int32 bufferSize, Boolean useAsync, String msgPath,

    Boolean
    > bFromProxy) +888
    > System.IO.FileStream..ctor(String path, FileMode mode, FileAccess

    access,
    > FileShare share, Int32 bufferSize) +44
    > clsFTP.DownloadFile(String sFileName, String sLocalFileName, Boolean
    > bResume) +120
    > clsFTP.DownloadFile(String sFileName, String sLocalFileName) +13
    > ASP.test_aspx.Page_Load() in C:\ClientsWeb\test.aspx:20
    > System.Web.Util.ArglessEventHandlerDelegateProxy.Callback(Object

    sender,
    > EventArgs e) +10
    > System.Web.UI.Control.OnLoad(EventArgs e) +67
    > System.Web.UI.Control.LoadRecursive() +35
    > System.Web.UI.Page.ProcessRequestMain() +731
    >
    >
     
    Morgan, Dec 17, 2003
    #2
    1. Advertising

  3. Have you turned on impersonate in .config file? If yes, your web code run
    under the the authenticated user of IIS; then you have configured the
    Anonymous access you must add the permission for the account configured in
    IIS (IUSR_machinename is the default on II5). Else if you have configured
    the basic or windows integrated, you must add the permission for the
    requester user.
    I think that add a simple code the write the process identity could help you
    to troubleshoot what's happens:
    Response.Write("Identity: " +
    System.Security.Principal.WindowsIdentity.GetCurrent.Name)

    HtH,
    Andrea

    --
    This posting is provided "AS IS" with no warranties, and confers no rights.

    "Brent Bigler" <> wrote in message
    news:...
    > The computer: W2K server, domain controller, Microsoft.Net Framework 1.1
    >
    > ========================
    > The error message:
    >
    > Access to the path "c:\fanmail\newfiles" is denied
    > ...
    >
    > Exception Details: System.UnauthorizedAccessException: Access to the path
    > "c:\fanmail\newfiles" is denied
    >
    > *(see below for Stack Trace)
    >
    > ========================
    >
    > Fixes tried (but didn't work):
    >
    > 1. Added ASPNET account to c:\fanmail\newfiles and granted full permission
    > to resource;
    >
    > 2. Added ASPNET to Administrator group;
    >
    > 3. Changed machine.config processModel username setting to "SYSTEM";
    >
    > 4. Changed machine.config processModel username setting to

    "{Domain}\ASPNET"
    > along with the password setting to the appropriate password;
    >
    > 5. Sacrificed three chickens and a goat (in theory).
    >
    > =======================
    >
    > Most of the articles I've read say it's simply a permissions problem, like
    > the error reports. But it doesn't seem that any kind of permission

    changing
    > on the resource works. Anything else I should try?
    >
    > Thanks for any help!
    >
    > --Brent
    >
    > --------------------------------------------------------------------------

    --
    > -
    > The code class giving me the problems (from clsFTP, downloaded from
    > someplace on the Web)
    >
    > ===================================
    > Public Sub DownloadFile(ByVal sFileName As String, _
    > ByVal sLocalFileName As String, _
    > ByVal bResume As Boolean)
    > Dim st As Stream
    > Dim output As FileStream
    > Dim cSocket As Socket
    > Dim offset, npos As Long
    >
    > If (Not (m_bLoggedIn)) Then
    > Login()
    > End If
    >
    > SetBinaryMode(True)
    >
    > If (sLocalFileName.Equals("")) Then
    > sLocalFileName = sFileName
    > End If
    >
    > If (Not (File.Exists(sLocalFileName))) Then
    > st = File.Create(sLocalFileName) '<----Error here, I presume
    > st.Close()
    > End If
    >
    > output = New FileStream(sLocalFileName, FileMode.Open)
    > cSocket = CreateDataSocket()
    > offset = 0
    >
    > If (bResume) Then
    > offset = output.Length
    >
    > If (offset > 0) Then
    > SendCommand("REST " & offset)
    > If (m_iRetValue <> 350) Then
    > 'throw new IOException(reply.Substring(4));
    > 'Some servers may not support resuming.
    > offset = 0
    > End If
    > End If
    >
    > If (offset > 0) Then
    > npos = output.Seek(offset, SeekOrigin.Begin)
    > End If
    > End If
    >
    > SendCommand("RETR " & sFileName)
    >
    > If (Not (m_iRetValue = 150 Or m_iRetValue = 125)) Then
    > MessageString = m_sReply
    > Throw New IOException(m_sReply.Substring(4))
    > End If
    >
    > Do While (True)
    > m_aBuffer.Clear(m_aBuffer, 0, m_aBuffer.Length)
    > m_iBytes = cSocket.Receive(m_aBuffer, m_aBuffer.Length, 0)
    > output.Write(m_aBuffer, 0, m_iBytes)
    >
    > If (m_iBytes <= 0) Then
    > Exit Do
    > End If
    > Loop
    >
    > output.Close()
    > If (cSocket.Connected) Then
    > cSocket.Close()
    > End If
    >
    > ReadReply()
    > If (Not (m_iRetValue = 226 Or m_iRetValue = 250)) Then
    > MessageString = m_sReply
    > Throw New IOException(m_sReply.Substring(4))
    > End If
    >
    > End Sub
    > ===========================
    >
    > Stack Trace:
    >
    > [UnauthorizedAccessException: Access to the path "c:\FanMail\NewFiles" is
    > denied.]
    > System.IO.__Error.WinIOError(Int32 errorCode, String str) +393
    > System.IO.FileStream..ctor(String path, FileMode mode, FileAccess

    access,
    > FileShare share, Int32 bufferSize, Boolean useAsync, String msgPath,

    Boolean
    > bFromProxy) +888
    > System.IO.FileStream..ctor(String path, FileMode mode, FileAccess

    access,
    > FileShare share, Int32 bufferSize) +44
    > clsFTP.DownloadFile(String sFileName, String sLocalFileName, Boolean
    > bResume) +120
    > clsFTP.DownloadFile(String sFileName, String sLocalFileName) +13
    > ASP.test_aspx.Page_Load() in C:\ClientsWeb\test.aspx:20
    > System.Web.Util.ArglessEventHandlerDelegateProxy.Callback(Object

    sender,
    > EventArgs e) +10
    > System.Web.UI.Control.OnLoad(EventArgs e) +67
    > System.Web.UI.Control.LoadRecursive() +35
    > System.Web.UI.Page.ProcessRequestMain() +731
    >
    >
     
    Andrea D'Onofrio [MSFT], Dec 18, 2003
    #3
  4. Brent Bigler

    Brent Bigler Guest

    Thanks for both your replies!

    I added the IUSR account to the resource with no luck. I also checked to see
    which identity is being used via Response.Write("Identity: " +
    System.Security.Principal.WindowsIdentity.GetCurrent.Name + "<br/>")

    (clever idea!) and found that it's the ASPNET user. That user has all the
    permissions in the world, aside from being an Administrator. I really am
    stumped!

    --Brent
     
    Brent Bigler, Dec 18, 2003
    #4
  5. Brent Bigler

    Morgan Guest

    What OS are you running? If Win2K3, then I can't help... ;)
    "Brent Bigler" <> wrote in message
    news:...
    > The computer: W2K server, domain controller, Microsoft.Net Framework 1.1
    >
    > ========================
    > The error message:
    >
    > Access to the path "c:\fanmail\newfiles" is denied
    > ...
    >
    > Exception Details: System.UnauthorizedAccessException: Access to the path
    > "c:\fanmail\newfiles" is denied
    >
    > *(see below for Stack Trace)
    >
    > ========================
    >
    > Fixes tried (but didn't work):
    >
    > 1. Added ASPNET account to c:\fanmail\newfiles and granted full permission
    > to resource;
    >
    > 2. Added ASPNET to Administrator group;
    >
    > 3. Changed machine.config processModel username setting to "SYSTEM";
    >
    > 4. Changed machine.config processModel username setting to

    "{Domain}\ASPNET"
    > along with the password setting to the appropriate password;
    >
    > 5. Sacrificed three chickens and a goat (in theory).
    >
    > =======================
    >
    > Most of the articles I've read say it's simply a permissions problem, like
    > the error reports. But it doesn't seem that any kind of permission

    changing
    > on the resource works. Anything else I should try?
    >
    > Thanks for any help!
    >
    > --Brent
    >
    > --------------------------------------------------------------------------

    --
    > -
    > The code class giving me the problems (from clsFTP, downloaded from
    > someplace on the Web)
    >
    > ===================================
    > Public Sub DownloadFile(ByVal sFileName As String, _
    > ByVal sLocalFileName As String, _
    > ByVal bResume As Boolean)
    > Dim st As Stream
    > Dim output As FileStream
    > Dim cSocket As Socket
    > Dim offset, npos As Long
    >
    > If (Not (m_bLoggedIn)) Then
    > Login()
    > End If
    >
    > SetBinaryMode(True)
    >
    > If (sLocalFileName.Equals("")) Then
    > sLocalFileName = sFileName
    > End If
    >
    > If (Not (File.Exists(sLocalFileName))) Then
    > st = File.Create(sLocalFileName) '<----Error here, I presume
    > st.Close()
    > End If
    >
    > output = New FileStream(sLocalFileName, FileMode.Open)
    > cSocket = CreateDataSocket()
    > offset = 0
    >
    > If (bResume) Then
    > offset = output.Length
    >
    > If (offset > 0) Then
    > SendCommand("REST " & offset)
    > If (m_iRetValue <> 350) Then
    > 'throw new IOException(reply.Substring(4));
    > 'Some servers may not support resuming.
    > offset = 0
    > End If
    > End If
    >
    > If (offset > 0) Then
    > npos = output.Seek(offset, SeekOrigin.Begin)
    > End If
    > End If
    >
    > SendCommand("RETR " & sFileName)
    >
    > If (Not (m_iRetValue = 150 Or m_iRetValue = 125)) Then
    > MessageString = m_sReply
    > Throw New IOException(m_sReply.Substring(4))
    > End If
    >
    > Do While (True)
    > m_aBuffer.Clear(m_aBuffer, 0, m_aBuffer.Length)
    > m_iBytes = cSocket.Receive(m_aBuffer, m_aBuffer.Length, 0)
    > output.Write(m_aBuffer, 0, m_iBytes)
    >
    > If (m_iBytes <= 0) Then
    > Exit Do
    > End If
    > Loop
    >
    > output.Close()
    > If (cSocket.Connected) Then
    > cSocket.Close()
    > End If
    >
    > ReadReply()
    > If (Not (m_iRetValue = 226 Or m_iRetValue = 250)) Then
    > MessageString = m_sReply
    > Throw New IOException(m_sReply.Substring(4))
    > End If
    >
    > End Sub
    > ===========================
    >
    > Stack Trace:
    >
    > [UnauthorizedAccessException: Access to the path "c:\FanMail\NewFiles" is
    > denied.]
    > System.IO.__Error.WinIOError(Int32 errorCode, String str) +393
    > System.IO.FileStream..ctor(String path, FileMode mode, FileAccess

    access,
    > FileShare share, Int32 bufferSize, Boolean useAsync, String msgPath,

    Boolean
    > bFromProxy) +888
    > System.IO.FileStream..ctor(String path, FileMode mode, FileAccess

    access,
    > FileShare share, Int32 bufferSize) +44
    > clsFTP.DownloadFile(String sFileName, String sLocalFileName, Boolean
    > bResume) +120
    > clsFTP.DownloadFile(String sFileName, String sLocalFileName) +13
    > ASP.test_aspx.Page_Load() in C:\ClientsWeb\test.aspx:20
    > System.Web.Util.ArglessEventHandlerDelegateProxy.Callback(Object

    sender,
    > EventArgs e) +10
    > System.Web.UI.Control.OnLoad(EventArgs e) +67
    > System.Web.UI.Control.LoadRecursive() +35
    > System.Web.UI.Page.ProcessRequestMain() +731
    >
    >
     
    Morgan, Dec 20, 2003
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?RGF2aWQgVGhpZWxlbg==?=

    Does a resource have to have all phrases in it?

    =?Utf-8?B?RGF2aWQgVGhpZWxlbg==?=, Jan 30, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    382
    Neil Ni
    Feb 3, 2006
  2. Heinrich Moser
    Replies:
    1
    Views:
    466
    Heinrich Moser
    Mar 27, 2008
  3. Manfred Braun

    TreeView permission problem;Where do I need to have access??

    Manfred Braun, Jul 17, 2003, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    176
    Manfred Braun
    Jul 18, 2003
  4. Devin
    Replies:
    5
    Views:
    138
    Daniel Crichton
    Oct 28, 2008
  5. Andyza
    Replies:
    1
    Views:
    869
    Bob Barrows
    Sep 30, 2009
Loading...

Share This Page