M
Matthew Holton
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.AppSettings.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
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.AppSettings.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
("UserName", "Password", "MACHINE/DOMAIN");-----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.PermitOnly, Write =
"F:\\DirectoryName")]
public bool DeleteDirectory(string Directory)
{
//ImpersonateUser
(FileIOPermissionAccess.AllAccess, FTPPath);string FTPPath = @"f:\DirectoryName\" + Directory;
FileIOPermission f; // = new FileIOPermission (PermissionState.None);
f = new FileIOPermission