Impersonate



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
.



Relevant Pages

  • RE: code to create five different sql queries
    ... Excel file, not five Excel files. ... Private Sub ExportToExcelBtn_Click ... Dim IR_ListAs String ...
    (microsoft.public.access.formscoding)
  • Re: Changing Device Wallpaper in Background
    ... Anyway, I don't, of course, have the source for the Windows Mobile shell, ... Where can I find a list of the valid parameter values SendMessage takes, ... Private Sub WPMaster_PPC_Load(ByVal sender As Object, ... Dim intFilesInFolder As Integer = ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: Automate Excel
    ... I'm guessing on the Set oSheet = oBook.Worksheets, ... >quick....now it just opens my Excel file once, ... > Dim oExcel As Excel.Application ... > Exit Sub ...
    (microsoft.public.access.formscoding)
  • App crashes on Windows98
    ... I installed framework 2 and windows installer 2 on the windows 98 ... Private Sub btnQuickQuoteOK_Click(ByVal sender As System.Object, ... exception is not handled. ... Dim caller As New AsyncMethodCaller(AddressOf ...
    (microsoft.public.dotnet.framework.aspnet)
  • RE: excel to access problem
    ... update every record with its "Total Charges" from the excel file (which comes ... Charges" which should be the one from the excel file. ... Private Sub Command280_Click ... Dim xlApp As Excel.Application ...
    (microsoft.public.access.modulesdaovba)