473,608 Members | 2,054 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Impersonation Problem

I'm having a difficult time with impersonation. I've created an
impersonation class. Here is the code below:

******Impersona tion Class Code*********
Imports System
Imports System.Web.Secu rity
Imports System.Runtime. InteropServices
Imports System.Security .Principal
Imports System.Director yServices
Imports System.Security .Permissions
Public Class SecurityHelpers
Private Sub New()
MyBase.New()

End Sub

Declare Auto Function LogonUser Lib "advapi32.d ll" (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
Declare Auto Function CloseHandle Lib "kernel32.d ll" (ByVal handle
As IntPtr) As Boolean

Public Shared Function CreateIdentity( ByVal userName As String,
ByVal domain As String, ByVal password As String) As WindowsIdentity
Dim tokenHandle As IntPtr = New IntPtr(0)
Const LOGON32_PROVIDE R_KERBEROS As Integer = 3
Const LOGON32_LOGON_I NTERACTIVE As Integer = 2
tokenHandle = IntPtr.Zero
Dim returnValue As Boolean = LogonUser(userN ame, domain,
password, LOGON32_LOGON_I NTERACTIVE, LOGON32_PROVIDE R_KERBEROS,
tokenHandle)
If (False = returnValue) Then
Dim ret As Integer = Marshal.GetLast Win32Error
Throw New System.Unauthor izedAccessExcep tion(("LogonUse r
failed with error code: " + ret))
End If
Dim id As WindowsIdentity = New WindowsIdentity (tokenHandle)
CloseHandle(tok enHandle)
Return id
End Function
End Class

*********Here is how I'm calling it in my code:*********

Dim wic As WindowsImperson ationContext = Nothing
wic = SecurityHelpers .CreateIdentity (username, domain,
password).Imper sonate
'Upload the file
wic.undo

The error only occurs when I'm on trying to access resources on another
server. I can upload a file to the other server, but I can't access any
of the file's properties. Here is the error below:

********Error** *********
Impersonation failure.
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more

information about the error and where it originated in the code.

Exception Details: System.Web.Http Exception: Impersonation failure.
Portion of stack trace:
HttpException (0x80004005): Impersonation failure.]
System.Web.Impe rsonationSuspen dContext.GetCur rentToken() +215
System.Web.Impe rsonationSuspen dContext.Suspen d() +53
System.Web.Http Context.GetConf ig(String name) +104

System.Web.Conf iguration.HttpC onfigurationSys temBase.System. Configuration.I ConfigurationSy stem.GetConfig( String
configKey) +22
System.Configur ation.Configura tionSettings.Ge tConfig(String
sectionName) +69
System.Configur ation.Configura tionSettings.ge t_AppSettings() +26

I would appreciate any help you could give me. Thanks.

Mar 29 '06 #1
0 1253

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

Similar topics

3
5157
by: Chris | last post by:
Hello all, Here is my problem. I have a windows service (C#) that is supposed to move files from/to the local drive to/from a UNC share (\\domainserver\share). The service is running on a Win3k server not connected to a domain, as a local user. The service impersonates a local user (on domainserver) that has full permissions to that share. Any File.Move, File.Copy operations are successfull. Any Directory.GetFiles fail with "Logon...
12
2557
by: Anil Krishnamurthy | last post by:
We have an ASP.NET application that uses COM objects through Interop. The web application requires access to network and database resources and hence, needs to impersonate a domain account. The problem is that even when it is configured to run under a certain identity through Web.config, the impersonation is not carried through to COM library. Consequently, the code in COM object runs under a local account and any code that needs to access...
1
3951
by: techfuzz | last post by:
I'm posting my problem experience and solution I found here for other ASP.NET developers. I have a web application that uses Forms Authentication with Active Directory to control access. In this web application, I have search page that utilizes the Windows Indexing Service (MSIDXS provider). For reasons I'm not aware of at this time, setting <identity impersonation="true" /> in the web.config causes an error whenever you try to search.
8
3445
by: Anthony Munter | last post by:
I have a web application with impersonate=”true” in Web.config and on my own logon page I allow the user to either - specify a userid/password for the app to impersonate when calling legacy COM objects - or, just use the interactive user If they choose to use the interactive option, the impersonate="true" means that the process runs under the interactiv user (which I've confirmed works correctly). If they specify a userid/password, I...
3
1571
by: Jake Smythe | last post by:
Hello, I have some code that impersonates a user upon launching of the application. We now have the need to run some command line items. The impersonation doesn't seem to pass to the commands being run. Is there a way to do this? Basically looking for a way do a runas on a command line through an application. Thanks in advance. Below is some sample code, where we need to impersonate an admin to run command line code. Private Sub test
11
2842
by: Phil | last post by:
Hi, I've currently setup a local user as described in: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnne...
4
1785
by: David Cablalero | last post by:
I have a windows service which every night checks a SQL Server database for some data and business rules. The application can access different DBs with the same structure, to tell the service which database to check I created local users and assigned each of them a different default DB in SQL Server, then, in the windows service I impersonate each user and then access the DB, when the connection to the DB is made, the default DB for the...
8
3518
by: Marco Mechelli | last post by:
Hello, i'm facing with the following problem while using the Job API during an impersonation. I have a main process that needs to do the following: 1. Creates a new Job Object that will be used to handle its children. 2. Create a new process (either by CreateProcessW() or by CreateProcessWithLogonW() for user impersonation).
0
1013
by: Brian | last post by:
Greetings! I'm trying to find a good place to call SqlCacheDependency.Start() and I'm running into some issues. I know this isn't a SQL forum, but this seems more like an ASP.NET lifetime problem. I treid Application_Start() but we're running with anon access and impersonation, and impersonation is not 'on' yet. I considered impersonating my user in Application_Start() but I'm not
0
8087
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, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
8493
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
8179
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
8365
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
6847
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 projectplanning, coding, testing, and deploymentwithout 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...
0
5499
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4053
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1620
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1363
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.