Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / July 2007

Tip: Looking for answers? Try searching our database.

Identity Impersonate - Multithreading?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
rowe_newsgroups - 12 Jul 2007 18:35 GMT
Forgive me if I'm being ignorant, but is the identity tab in the
web.config ignored by background threads?

I have written a class that has both a synchronous and asynchronous
mode for querying an Access database located on a network share. To
get access to the network share I am using the identity tag with
impersonate="true" and a valid user name and password. The odd thing
is that the synchronous method runs fine, but when multithreaded, I
get an OleDb exception saying the the Jet OleDb provider could not
find the path specified in the connection string - it's as if the
identity tag is being ignored!?

Thanks in advance for any input!

Thanks,

Seth Rowe
Juan T. Llibre - 12 Jul 2007 18:51 GMT
IIRC, The background thread executes under the Application Pool identity.
Make sure you pass the correct identity to the Jet OleDb provider.

Review this article/download the code and see if your code
conforms to what Joshua says works for him :

http://flimflan.com/blog/SafelyRunningBackgroundThreadsInASPNET20.aspx

Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
> Forgive me if I'm being ignorant, but is the identity tab in the
> web.config ignored by background threads?
[quoted text clipped - 13 lines]
>
> Seth Rowe
rowe_newsgroups - 12 Jul 2007 19:14 GMT
On Jul 12, 1:51 pm, "Juan T. Llibre" <nomailrepl...@nowhere.com>
wrote:
> IIRC, The background thread executes under the Application Pool identity.
> Make sure you pass the correct identity to the Jet OleDb provider.
[quoted text clipped - 26 lines]
>
> > Seth Rowe

Oh how I wish I would have posted this yesterday!

I'll give your link a read as well as bruce's suggestions and let you
know how it turns out.

Thanks to both of you!

Thanks,

Seth Rowe
rowe_newsgroups - 13 Jul 2007 15:57 GMT
> On Jul 12, 1:51 pm, "Juan T. Llibre" <nomailrepl...@nowhere.com>
> wrote:
[quoted text clipped - 40 lines]
>
> Seth Rowe

Okay, in the end I didn't use either of your suggestions, but crafted
my own based on some API documentation I read through.

Below is my solution if any future archive browsers need it:

//////////////////
Imports System.Security.Principal
Imports System.Runtime.InteropServices

Public Class MyClassToBeThreaded

   <DllImport("advapi32.dll")> _
   Protected 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 IntPtr) As
Boolean
   End Function

   '// This is the thread to be called asynchronously,
   '// so do the impersonation calls here
   Public Sub DoTheWork()
       Try
           Dim hToken As IntPtr
           If LogonUser("username", "domain", "password", 2, 0,
hToken) Then
               Using wi As WindowsIdentity = New
WindowsIdentity(hToken), wic As WindowsImpersonationContext =
wi.Impersonate()
                   '// Do the actually work here

               End Using
           End If
       Catch
           '// Handle the exception if the impersonation
           '// blows up in your face :-)
       End Try
   End Sub

End Class
/////////////////////

Thanks,

Seth Rowe
Juan T. Llibre - 13 Jul 2007 18:57 GMT
re:
!> Okay, in the end I didn't use either of your suggestions, but crafted
!> my own based on some API documentation I read through.

Fantastic, Seth!

Thanks for sharing the code.
It should help someone down the line...

Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
> On Jul 12, 1:51 pm, "Juan T. Llibre" <nomailrepl...@nowhere.com>
> wrote:
[quoted text clipped - 42 lines]
>
> Seth Rowe

Okay, in the end I didn't use either of your suggestions, but crafted
my own based on some API documentation I read through.

Below is my solution if any future archive browsers need it:

//////////////////
Imports System.Security.Principal
Imports System.Runtime.InteropServices

Public Class MyClassToBeThreaded

   <DllImport("advapi32.dll")> _
   Protected 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 IntPtr) As
Boolean
   End Function

   '// This is the thread to be called asynchronously,
   '// so do the impersonation calls here
   Public Sub DoTheWork()
       Try
           Dim hToken As IntPtr
           If LogonUser("username", "domain", "password", 2, 0,
hToken) Then
               Using wi As WindowsIdentity = New
WindowsIdentity(hToken), wic As WindowsImpersonationContext =
wi.Impersonate()
                   '// Do the actually work here

               End Using
           End If
       Catch
           '// Handle the exception if the impersonation
           '// blows up in your face :-)
       End Try
   End Sub

End Class
/////////////////////

Thanks,

Seth Rowe
bruce barker - 12 Jul 2007 19:04 GMT
when the NT creates a thread, the identity is the process identity, not
the creating threads identity.

to get around this, you can pass the credentials to the new thread. you
will need to use the win api -- see DuplicateToken. you may also need a
RevertToSelf. you then pass the token to to new WindowsIdentity, and
call impersonate method.

google these terms to get samples.

-- bruce (sqlwork.com)

> Forgive me if I'm being ignorant, but is the identity tab in the
> web.config ignored by background threads?
[quoted text clipped - 13 lines]
>
> Seth Rowe

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.