Access to Path is denied

Ask a Question related to ASP.NET Web Services, Design and Development.

  1. #1

    Default Re: Access to Path is denied

    What account is your webservice running under? aspnet? Does aspnet have
    access to the directory?

    Maarten


    "Eric Levin" <eric@soundsite.com> wrote in message
    news:OdTrgmobDHA.2820@tk2msftngp13.phx.gbl...
    > I am trying to call a DirectoryInfo.Delete function from a Web Service but
    > am getting an Access Denied Error:
    > System.UnauthorizedAccessException: Access to Path "..." is Denied.
    >
    > I have tried using Impersonation and setting the
    FileIOPermissionAttributes,
    > but am still getting the same error:
    >
    > Thanks,
    >
    > [WebMethod]
    > //[FileIOPermissionAttribute(SecurityAction.PermitOnl y, Write =
    > "F:\\DirectoryName")]
    > public bool DeleteDirectory(string Directory)
    > {
    > //ImpersonateUser("UserName", "Password", "MACHINE/DOMAIN");
    > string FTPPath = @"f:\DirectoryName\" + Directory;
    > FileIOPermission f; // = new FileIOPermission(PermissionState.None);
    > f = new FileIOPermission(FileIOPermissionAccess.AllAccess, FTPPath);
    > DirectoryInfo ftp = new DirectoryInfo(FTPPath);
    > ftp.Delete(true);
    > ftp.Refresh();
    > //StopImpersonateUser();
    > if (ftp.Exists == true)
    > return false;
    > else
    > return true;
    > }
    >
    > Eric Levin
    > Sounddogs.com
    >
    >
    >
    >
    >
    >
    >

    Maarten Guest

  2. Similar Questions and Discussions

    1. Access to path is denied...
      I'm trying to test/check contents of a dataset by writing it to an xml file on the server, but get this error above. The suggestion to grant...
    2. Access to path denied
      I have a question. I am running Windows 2003 Server with Framework 1.1. I have an application that has XML config files within it that drive part...
    3. Access to the path is denied
      This is error message I've got. Any suggestion would be appreciated. Server Error in '/WebDirectory' Application. ...
    4. System.UnauthorizedAccessException: Access to the path is denied
      Server Error in '/BIP' Application. ----------------------------------------------------------- --------------------- Access to the path...
    5. Access to the path ...\\dynamic_images is denied. What Happens???
      I have designed a report that uses the CrystalReportViewer which works fine on my local machine. I created a setup to install Crystal Report in my...
  3. #2

    Default Access to Path is denied

    Eric,

    I had a similar issue, here is how i resolved it:

    1. require the webservice to use NT AUTH, set that up in
    IIS for that virtual root.

    2. Refresh you webservice reference

    3. In your webservice reference, open Reference.vb and
    put in

    .... (VB Snippet, convert to C#)
    Protected Overrides Function GetWebRequest(ByVal uri
    As System.Uri) As System.Net.WebRequest

    'This will force presentation of credentials
    'Turns off persistance with wp
    Dim mHttpWebRequest As System.Net.HttpWebRequest =
    MyBase.GetWebRequest(uri)
    mHttpWebRequest.KeepAlive = False
    Return mHttpWebRequest

    End Function
    ....

    This will need to be put in each time you refresh your
    webservice reference. It forces the credentials to be
    evaluated each time a request is made. The alternative
    is, once a sucessful AUTH is made, noone else is validated.

    4. Before you call the webservice.DeleteDirectory

    .... (VB Snippet, convert to C#)


    'Create an instance of our webservice
    Dim objImpersonator As WebService.FileIO = New
    WebService.FileIO()

    'Get the location of our webservice
    objImpersonator.Url =
    System.Configuration.ConfigurationSettings.AppSett ings.Get
    ("WebService.FileIO.Connector")

    'Create credentials to connect to our webserivce
    Dim objCredential As System.Net.NetworkCredential
    Dim objCache As New System.Net.CredentialCache()
    objCredential = New System.Net.NetworkCredential
    (sUserName, sPassword, sDomainName)
    'objCache.Add(New System.Uri
    (objImpersonator.Url), "Basic", objCredential)

    'Present our credentials
    objImpersonator.Credentials =
    objCredential 'objCache

    iRet = objImpersonator.DeleteDirectory
    (sPathToDelete)

    ....

    5. Place your web serivce server on a DMZ, but away from
    public eyes. This way you wont need a certificate and
    wont have to worry about people monitoring this traffic
    and getting UID/PWD.

    HTH,


    Matthew Holton
    >-----Original Message-----
    >I am trying to call a DirectoryInfo.Delete function from
    a Web Service but
    >am getting an Access Denied Error:
    >System.UnauthorizedAccessException: Access to Path "..."
    is Denied.
    >
    >I have tried using Impersonation and setting the
    FileIOPermissionAttributes,
    >but am still getting the same error:
    >
    >Thanks,
    >
    >[WebMethod]
    >//[FileIOPermissionAttribute(SecurityAction.PermitOnl y,
    Write =
    >"F:\\DirectoryName")]
    >public bool DeleteDirectory(string Directory)
    >{
    > //ImpersonateUser
    ("UserName", "Password", "MACHINE/DOMAIN");
    > string FTPPath = @"f:\DirectoryName\" + Directory;
    > FileIOPermission f; // = new FileIOPermission
    (PermissionState.None);
    > f = new FileIOPermission
    (FileIOPermissionAccess.AllAccess, FTPPath);
    > DirectoryInfo ftp = new DirectoryInfo(FTPPath);
    > ftp.Delete(true);
    > ftp.Refresh();
    > //StopImpersonateUser();
    > if (ftp.Exists == true)
    > return false;
    > else
    > return true;
    >}
    >
    >Eric Levin
    >Sounddogs.com
    >
    >
    >
    >
    >
    >
    >
    >.
    >
    Matthew Holton Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139