|
| Access UNC Share from Webservice - HELP |
|
|
|
|
| Messages |
|
Related Types |
This message was discovered on microsoft.public.dotnet.framework.aspnet.webservices.
| Daniel Bruske |
HI,
i need to do file operations (read-write) using UNC shares. I tried web.config impersonation and runtime impersonation (with domain admin account) but i always get a "directory/file not found" exception. I tried the same thing with an ASP.NET page (.aspx) and it worked fine. I think it's a webservice permission issue.
Can anyone help me??
|
|
|
| |
|
| |
| |
| Wade Mascia [MS] |
HI,
i need to do file operations (read-write) using UNC shares. I tried web.config impersonation and runtime impersonation (with domain admin account) but i always get a "directory/file not found" exception. I tried the same thing with an ASP.NET page (.aspx) and it worked fine. I think it's a webservice permission issue.
Can anyone help me??
|
|
|
| |
|
| |
| |
| Daniel Bruske |
Hi,
thanks for your help, but it still doesnt work.....sniff
i made this simple function to test it under .asmx and .aspx:
<WebMethod()> Public Function createtxtfile(ByVal path As String) As String
Dim myimp As New impersonation()
Dim strexception As String
myimp.impersonateuser("Administrator", "XXXXXXXXXX", "atop.it")
Try
Dim mytxt As IO.StreamWriter = IO.File.CreateText(path)
mytxt.Write("TEST")
mytxt.Close()
Catch e As Exception
strexception = e.ToString
End Try
If Not IsNothing(strexception) Then
createtxtfile = System.Security.Principal.WindowsIdentity.GetCurrent.Name.ToString & " || " & strexception
Else
createtxtfile = System.Security.Principal.WindowsIdentity.GetCurrent.Name.ToString
End If
myimp.revertimpersonation()
End Function
I tested it with different UNC shares, under aspx it worked with all shares i tested, under .asmx it worked only on UNC shares of the server which hosts the webservice and not on shares of other PCs. The Function returns ALWAYS the correct WindowsIdentity ("ATOP\Administrator" which is my Domain Admin). Then i tried to use FileMon, it shows no entries when i get "System.UnauthorizedAccessException" using the webservice and shows correct entries when i use local UNC shares or when i use .aspx.
Any Idea??
Thanks,
Daneel
"Wade Mascia [MS]" <Click here to reveal e-mail address> ha scritto nel messaggio news:YXWHGm$3BHA.1592@cpmsftngxa07... [Original message clipped]
|
|
|
| |
|
|
| |
|
| |
| Daniel Bruske |
Hi,
sorry, it's me....again. ;)
I did other tests.....
I created a UNC share with anonymous access rights and tried to create a textfile with the webservice. Then i went to take a look to the fileowner property. Files created locally have "ATOP\administrator" as owner, and files created on remote shares have "NT AUTHORITY/ANONYMOUS" as owner.
There must be something wrong with impersonation, i use this class:
Imports System
Imports System.Runtime.InteropServices
Imports System.Security.Principal
Imports System.Security.Permissions
Public Class impersonation
Dim token1 As Integer
Dim token2 As IntPtr
Dim newidentity As WindowsIdentity
Dim impcontext As WindowsImpersonationContext
Dim systemdir As String
<DllImport("advapi32.dll")> _
Public Shared Function LogonUser(ByVal lpszUsername As String, ByVal lpszDomain As String, ByVal lpszPassword As String, _
ByVal dwLogonType As Integer, ByVal dwLogonProvider As Integer, ByRef phToken As Integer) As Boolean
End Function
Public Function impersonateuser(ByVal username As String, ByVal password As String, ByVal domain As String) As Boolean
Dim loggedOn As Boolean = LogonUser(username, domain, password, 3, 0, token1)
If loggedOn Then
token2 = New IntPtr(token1)
newidentity = WindowsIdentity.GetCurrent
impcontext = newidentity.Impersonate(token2)
End If
Return loggedOn
End Function
Public Sub revertimpersonation()
impcontext.Undo()
newidentity = Nothing
End Sub
End Class
Thanks for your help,
Daniel
"Wade Mascia [MS]" <Click here to reveal e-mail address> ha scritto nel messaggio news:YXWHGm$3BHA.1592@cpmsftngxa07... [Original message clipped]
|
|
|
| |
|
| |
| |
| Wade Mascia [MS] |
Hi Daniel,
I would say the problem is in the impersonation. I ran out of time to run sample code, etc., today but this is what I know: you can't impersonate from an asmx thread that is already impersonating. I believe this to also be true for aspx, but I didn't have time to confirm today. If you call RevertToSelf before calling LogonUser it should work. Also, if you simply want to impersonate a particular user you should just use the <identity> tag in the web.config. You can also use this to impersonate the client (if using basic or integrated auth. on the virtual directory).
I just wanted to get something out before I left today so let me know if I was too vague or you have questions.
HTH,
~Wade Mascia Developer Support Engineer - Distributed Services, MTS/COM+ & ASP/COM Microsoft Corporation
And now, a word from our lawyers: "This posting is provided 'AS IS' with no warranties, and confers no rights." -------------------- From: "Daniel Bruske" <Click here to reveal e-mail address> References: <064a01c1dfdb$135da2a0$9de62ecf@tkmsftngxs01> <YXWHGm$3BHA.1592@cpmsftngxa07> Subject: Re: Access UNC Share from Webservice - HELP Date: Wed, 10 Apr 2002 16:05:12 +0200 Lines: 144 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 Message-ID: <uXPjseJ4BHA.2848@tkmsftngp05> Newsgroups: microsoft.public.dotnet.framework.aspnet.webservices NNTP-Posting-Host: ppp-62-11-85-91.dialup.tiscali.it 62.11.85.91 Path: cpmsftngxa08!cpmsftngxa09!tkmsftngxs01!tkmsftngp01!tkmsftngp05 Xref: cpmsftngxa08 microsoft.public.dotnet.framework.aspnet.webservices:7378 X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webservices
Hi,
sorry, it's me....again. ;)
I did other tests.....
I created a UNC share with anonymous access rights and tried to create a textfile with the webservice. Then i went to take a look to the fileowner property. Files created locally have "ATOP\administrator" as owner, and files created on remote shares have "NT AUTHORITY/ANONYMOUS" as owner.
There must be something wrong with impersonation, i use this class:
Imports System
Imports System.Runtime.InteropServices
Imports System.Security.Principal
Imports System.Security.Permissions
Public Class impersonation
Dim token1 As Integer
Dim token2 As IntPtr
Dim newidentity As WindowsIdentity
Dim impcontext As WindowsImpersonationContext
Dim systemdir As String
<DllImport("advapi32.dll")> _
Public Shared Function LogonUser(ByVal lpszUsername As String, ByVal lpszDomain As String, ByVal lpszPassword As String, _
ByVal dwLogonType As Integer, ByVal dwLogonProvider As Integer, ByRef phToken As Integer) As Boolean
End Function
Public Function impersonateuser(ByVal username As String, ByVal password As String, ByVal domain As String) As Boolean
Dim loggedOn As Boolean = LogonUser(username, domain, password, 3, 0, token1)
If loggedOn Then
token2 = New IntPtr(token1)
newidentity = WindowsIdentity.GetCurrent
impcontext = newidentity.Impersonate(token2)
End If
Return loggedOn
End Function
Public Sub revertimpersonation()
impcontext.Undo()
newidentity = Nothing
End Sub
End Class
Thanks for your help,
Daniel
"Wade Mascia [MS]" <Click here to reveal e-mail address> ha scritto nel messaggio news:YXWHGm$3BHA.1592@cpmsftngxa07... [Original message clipped]
|
|
|
| |
|
| |
|
|
|
|
|
|
|
|
|
|
BootFX
Reliable and powerful .NET application framework. |
|
|
|
|
|
|