473,396 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Impersonation Problem

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

******Impersonation Class Code*********
Imports System
Imports System.Web.Security
Imports System.Runtime.InteropServices
Imports System.Security.Principal
Imports System.DirectoryServices
Imports System.Security.Permissions
Public Class SecurityHelpers
Private Sub New()
MyBase.New()

End Sub

Declare Auto Function LogonUser Lib "advapi32.dll" (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.dll" (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_PROVIDER_KERBEROS As Integer = 3
Const LOGON32_LOGON_INTERACTIVE As Integer = 2
tokenHandle = IntPtr.Zero
Dim returnValue As Boolean = LogonUser(userName, domain,
password, LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_KERBEROS,
tokenHandle)
If (False = returnValue) Then
Dim ret As Integer = Marshal.GetLastWin32Error
Throw New System.UnauthorizedAccessException(("LogonUser
failed with error code: " + ret))
End If
Dim id As WindowsIdentity = New WindowsIdentity(tokenHandle)
CloseHandle(tokenHandle)
Return id
End Function
End Class

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

Dim wic As WindowsImpersonationContext = Nothing
wic = SecurityHelpers.CreateIdentity(username, domain,
password).Impersonate
'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.HttpException: Impersonation failure.
Portion of stack trace:
HttpException (0x80004005): Impersonation failure.]
System.Web.ImpersonationSuspendContext.GetCurrentT oken() +215
System.Web.ImpersonationSuspendContext.Suspend() +53
System.Web.HttpContext.GetConfig(String name) +104

System.Web.Configuration.HttpConfigurationSystemBa se.System.Configuration.IConfigurationSystem.GetCo nfig(String
configKey) +22
System.Configuration.ConfigurationSettings.GetConf ig(String
sectionName) +69
System.Configuration.ConfigurationSettings.get_App Settings() +26

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

Mar 29 '06 #1
0 1234

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

Similar topics

3
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...
12
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...
1
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...
8
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...
3
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...
11
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
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...
8
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...
0
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...
0
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,...

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.