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 WindowsImpersonationContext = Nothing
Try
'
Response.Write(System.Security.Principal.WindowsId entity.GetCurrent().Name())
impContext = NetworkSecurity.ImpersonateUser("WEB",
Session("WinLogin"), Session("WinPassword"), LogonType.LOGON32_LOGON_NETWORK,
LogonProvider.LOGON32_PROVIDER_DEFAULT)
Catch ex As ApplicationException
' 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 WindowsImpersonationContext
Dim tokenHandle As IntPtr = New IntPtr(0)
Dim dupeTokenHandle As IntPtr = New IntPtr(0)
Try
Const SecurityImpersonation As Integer = 2
tokenHandle = IntPtr.Zero
dupeTokenHandle = IntPtr.Zero
Dim returnValue As Boolean = SecuUtil32.LogonUser(strLogin,
strDomain, strPwd, CType(logonType, Integer), CType(logonProvider, Integer),
tokenHandle)
If False = returnValue Then
Dim ret As Integer = Marshal.GetLastWin32Error
Dim strErr As String = String.Format("LogonUser failed
with error code : {0}", ret)
Throw New ApplicationException(strErr, Nothing)
End If
Dim retVal As Boolean =
SecuUtil32.DuplicateToken(tokenHandle, SecurityImpersonation, dupeTokenHandle)
If False = retVal Then
SecuUtil32.CloseHandle(tokenHandle)
Throw New ApplicationException("Failed to duplicate
token", Nothing)
End If
Dim newId As WindowsIdentity = New
WindowsIdentity(dupeTokenHandle)
Dim impersonatedUser As WindowsImpersonationContext =
newId.Impersonate
Return impersonatedUser
Catch ex As Exception
Throw New ApplicationException(ex.Message, ex)
End Try
Return Nothing
End Function 1 3066
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 WindowsImpersonationContext = Nothing Try ' Response.Write(System.Security.Principal.WindowsId entity.GetCurrent().Name()) impContext = NetworkSecurity.ImpersonateUser("WEB", Session("WinLogin"), Session("WinPassword"), LogonType.LOGON32_LOGON_NETWORK, LogonProvider.LOGON32_PROVIDER_DEFAULT)
Catch ex As ApplicationException ' 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 WindowsImpersonationContext Dim tokenHandle As IntPtr = New IntPtr(0) Dim dupeTokenHandle As IntPtr = New IntPtr(0) Try Const SecurityImpersonation As Integer = 2 tokenHandle = IntPtr.Zero dupeTokenHandle = IntPtr.Zero Dim returnValue As Boolean = SecuUtil32.LogonUser(strLogin, strDomain, strPwd, CType(logonType, Integer), CType(logonProvider, Integer), tokenHandle) If False = returnValue Then Dim ret As Integer = Marshal.GetLastWin32Error Dim strErr As String = String.Format("LogonUser failed with error code : {0}", ret) Throw New ApplicationException(strErr, Nothing) End If Dim retVal As Boolean = SecuUtil32.DuplicateToken(tokenHandle, SecurityImpersonation, dupeTokenHandle) If False = retVal Then SecuUtil32.CloseHandle(tokenHandle) Throw New ApplicationException("Failed to duplicate token", Nothing) End If Dim newId As WindowsIdentity = New WindowsIdentity(dupeTokenHandle) Dim impersonatedUser As WindowsImpersonationContext = newId.Impersonate Return impersonatedUser Catch ex As Exception Throw New ApplicationException(ex.Message, ex) End Try Return Nothing End Function This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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...
|
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...
|
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...
|
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...
|
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...
| |
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...
|
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...
|
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,...
|
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...
|
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...
|
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,...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
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...
|
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,...
|
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...
|
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...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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...
| |