473,796 Members | 2,586 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Impersonate problem

Hi

I am using below code for impersonating. Previosualy it was working fine.

Now its giving this error message. any idea how to resolve this.

LogonUser failed with error code : 87

thanks
bala

code:

Dim impContext As WindowsImperson ationContext = Nothing
Try
'
Response.Write( System.Security .Principal.Wind owsIdentity.Get Current().Name( ))
impContext = NetworkSecurity .ImpersonateUse r("WEB",
Session("WinLog in"), Session("WinPas sword"), LogonType.LOGON 32_LOGON_NETWOR K,
LogonProvider.L OGON32_PROVIDER _DEFAULT)

Catch ex As ApplicationExce ption
' impContext.Undo ()
Response.Write( ex.Message)
End Try

Public Shared Function ImpersonateUser (ByVal strDomain As String, ByVal
strLogin As String, ByVal strPwd As String, ByVal logonType As LogonType,
ByVal logonProvider As LogonProvider) As WindowsImperson ationContext
Dim tokenHandle As IntPtr = New IntPtr(0)
Dim dupeTokenHandle As IntPtr = New IntPtr(0)
Try
Const SecurityImperso nation As Integer = 2
tokenHandle = IntPtr.Zero
dupeTokenHandle = IntPtr.Zero
Dim returnValue As Boolean = SecuUtil32.Logo nUser(strLogin,
strDomain, strPwd, CType(logonType , Integer), CType(logonProv ider, Integer),
tokenHandle)
If False = returnValue Then
Dim ret As Integer = Marshal.GetLast Win32Error
Dim strErr As String = String.Format(" LogonUser failed
with error code : {0}", ret)
Throw New ApplicationExce ption(strErr, Nothing)
End If
Dim retVal As Boolean =
SecuUtil32.Dupl icateToken(toke nHandle, SecurityImperso nation, dupeTokenHandle )
If False = retVal Then
SecuUtil32.Clos eHandle(tokenHa ndle)
Throw New ApplicationExce ption("Failed to duplicate
token", Nothing)
End If
Dim newId As WindowsIdentity = New
WindowsIdentity (dupeTokenHandl e)
Dim impersonatedUse r As WindowsImperson ationContext =
newId.Impersona te
Return impersonatedUse r
Catch ex As Exception
Throw New ApplicationExce ption(ex.Messag e, ex)
End Try
Return Nothing
End Function
Nov 19 '05 #1
1 3119
exact error message is :
Token cannot be zero
"Bala" wrote:
Hi

I am using below code for impersonating. Previosualy it was working fine.
Now its giving this error message. any idea how to resolve this.

LogonUser failed with error code : 87

thanks
bala

code:

Dim impContext As WindowsImperson ationContext = Nothing
Try
'
Response.Write( System.Security .Principal.Wind owsIdentity.Get Current().Name( ))
impContext = NetworkSecurity .ImpersonateUse r("WEB",
Session("WinLog in"), Session("WinPas sword"), LogonType.LOGON 32_LOGON_NETWOR K,
LogonProvider.L OGON32_PROVIDER _DEFAULT)

Catch ex As ApplicationExce ption
' impContext.Undo ()
Response.Write( ex.Message)
End Try

Public Shared Function ImpersonateUser (ByVal strDomain As String, ByVal
strLogin As String, ByVal strPwd As String, ByVal logonType As LogonType,
ByVal logonProvider As LogonProvider) As WindowsImperson ationContext
Dim tokenHandle As IntPtr = New IntPtr(0)
Dim dupeTokenHandle As IntPtr = New IntPtr(0)
Try
Const SecurityImperso nation As Integer = 2
tokenHandle = IntPtr.Zero
dupeTokenHandle = IntPtr.Zero
Dim returnValue As Boolean = SecuUtil32.Logo nUser(strLogin,
strDomain, strPwd, CType(logonType , Integer), CType(logonProv ider, Integer),
tokenHandle)
If False = returnValue Then
Dim ret As Integer = Marshal.GetLast Win32Error
Dim strErr As String = String.Format(" LogonUser failed
with error code : {0}", ret)
Throw New ApplicationExce ption(strErr, Nothing)
End If
Dim retVal As Boolean =
SecuUtil32.Dupl icateToken(toke nHandle, SecurityImperso nation, dupeTokenHandle )
If False = retVal Then
SecuUtil32.Clos eHandle(tokenHa ndle)
Throw New ApplicationExce ption("Failed to duplicate
token", Nothing)
End If
Dim newId As WindowsIdentity = New
WindowsIdentity (dupeTokenHandl e)
Dim impersonatedUse r As WindowsImperson ationContext =
newId.Impersona te
Return impersonatedUse r
Catch ex As Exception
Throw New ApplicationExce ption(ex.Messag e, ex)
End Try
Return Nothing
End Function

Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1510
by: Yoshitha | last post by:
Hi I've to access registry and also get cpu id from the web application. First i wrote code to get cpuid from web application then i got cpu id. Next i wrote code to set value into a registry and when ran the application i got error that access to Registry is denied some thing. and then what i did is i changed the impersonate="true" from false in identity section of the machine.confog file. and then ran the application then i successfully...
1
4392
by: moemeelaung | last post by:
Hi ASP/Windows experts out there I really need help with this Impersonate function. I have machine A and B. A hosts my ASP page which is to create a user account on the machine B. The machine are not on Domain and not in AD environment. I userstand the the web page from A is to create a user account on B should use Impersonate function to log in as the user from the machine
12
3097
by: Nils M. Lunde | last post by:
Hi! I've made a Web Service using C# that is using impersonation. The WS is working fine on WinXP and Win2003Server, but I'm having problem getting it to work on Win2000. The problem is that in order to use LogonUser on Win2000, you have to have the SE_TCB_NAME privilege. Therefore I'm using the SSPLogonUser (http://support.microsoft.com/default.aspx?scid=http://support.microsoft.com:80/support/kb/articles/Q180/5/48.asp&NoWebContent=1)
8
33049
by: BLiTZWiNG | last post by:
After playing with the code shown and utilising Willy Denyottes' help, I have come to the conclusion that there is some form of difference between the managed WindowsIdentity.Impersonate() over the unmanaged ImpersonateLoggedOnUser(). Below is my code showing a file copy to a remote computer's shared folder using both WindowsImpersonationContext and ImpersonateLoggedOnUser/RevertToSelf, with the latter currently commented out. The...
6
2408
by: Erez Shor | last post by:
Hi, I need to build and asp page which access a remote windows server's registry and create a registry key. In order for the ASP page to be able to access the registry on the remote server I need it to run using credentials supplied by the user. When using basic authentication this is not an issue since the user has to provide a user name and password. But I don't want to use basic authentication so I created a login form and I am using...
2
7282
by: franzhe | last post by:
Hi all, in a simple ASP.Net application with resources in satellite assemblies I have the following problem: If I set <identity impersonate="true"/>, accessing a culture specific resource from a satellite assembly fails with the error message: "Could not find any resources appropriate for the specified culture (or the neutral culture) in the given assembly. ..."
2
2256
by: KaNos | last post by:
Hello world, I've made a webservice (c# v2) to install in a server IIS 6 on a Windows 2000 last SP. We can use the webservice in local, throw the pages wich present the methods, with a windows mode connection (<authentication mode="Windows"/>) if impersonate is false (<identity impersonate="false"/>). Note that i use the administrator user to be sure. But when I change impersonate element (<identity impersonate="true"/>) a system...
2
5279
by: rockdale | last post by:
Hi, all: My asp.net application calles MS speech 5.1 and generate a wav file on server's path. Everything runs perfectly on my development machine. But when I move the appl to production server, I always get ERROR: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)). First I thought its the permission problem, so I set permission of that directory to everyone (not an secure idea, but for test only). I found out that...
4
5815
by: =?Utf-8?B?QXZhRGV2?= | last post by:
ASP.Net 2. We are migrating to Windows 2008 64 bit Server with IIS 7 from Windows 2003 32 Bit with IIS 6. A few library classes we wrote uses impersonation in code like explained in this article: http://support.microsoft.com/?id=306158#4 This doesn't work in Windows 2008 Server, we receive the following exception:
5
7801
by: WT | last post by:
Hello, IIS6 on W2K3, .net 3.5, Sql 2005. All sp applied. My site is using windows authentication only and the web application connects to sql server residing on another server in the same domain using following connection string: <connectionStrings> <add name="My_ConnectionString"
0
9685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10242
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10200
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10021
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9061
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7558
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5453
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5582
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2931
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.