Impersonate
- From: zino <zino@xxxxxxxxxxxxxxx>
- Date: Fri, 8 Feb 2008 13:41:00 -0800
on Windows Xp and in ASP net 2.0 application,
I followed the example under the following link:
http://msdn2.microsoft.com/en-us/library/system.security.principal.windowsidentity.impersonate(VS.71).aspx
to save an Excel file, but I keep getting Access denied error.
(I have administartor privilege and I impersonate a domain account
(otherUser) that have administrator permissions too where the Excel file is
being saved)
note: without impersonation the code works fine under my account.
the web config file is set to :
<authentication mode="Windows"/>
<identity impersonate="true">
and "Integrated Windows Authentication" is the only thing checked in IIS
the web page :
sub Page_Load()
dim xl As myExcel = New myExcel()
xl.SaveExcel("c\test.xls")
end sub
class myExcel
function SaveExcel(filePath As String) As Boolean
dim xl As Excel.Application
dim wb As Excel.Workbook
.... .. . . ' code omitted
dim myImpersonate As New cls_impersonate
if myImpersonate.StartImpersonation(otherUser, otherPwd) Then
wb.SaveAs(filePath, FileFormat:=Excel.XlFileFormat.xlExcel7) '
generate Access is denied error
else
' ... .. .. .
end if
myImpersonate.UndoImpersonation()
end function
end class
class cls_impersonate
Private _impersonatedUser As WindowsImpersonationContext
Private _tokenHandle As New IntPtr(0)
function StartImpersonation(otherUser as string, otherPwd as string) as
boolean
'.. same as in the MSDN example and impersonation succeed without any error.
' but the following:
' WindowsIdentity.GetCurrent().Name --> return --> domain\otherUser
' while
' httpcontext.Current.User.Identity.Name --> return --> domain\myName
' which I don't understand
end function
sub UndoImpersonation
Me._impersonatedUser.Undo()
If Not System.IntPtr.op_Equality(Me._tokenHandle, IntPtr.Zero) Then
CloseHandle(Me._tokenHandle)
end sub
end class
thanks for help
.
- Follow-Ups:
- RE: Impersonate
- From: Steven Cheng[MSFT]
- RE: Impersonate
- Prev by Date: Re: SAML 2.0 and .NET integration
- Next by Date: how to update context.user without postback ...ing
- Previous by thread: SAML 2.0 and .NET integration
- Next by thread: RE: Impersonate
- Index(es):
Relevant Pages
|