ImpersonateUser Method

Impersonate another user to run current object.

[Syntax]
C++: HRESULT ImpersonateUser( BSTR User, BSTR Password, BSTR Domain, long* pVal )
Visual Basic: ImpersonateUser( User As String, _ 
                               Password As String, _ 
                               Domain As String ) As long
C#: long ImpersonateUser( string User, string Password, string Domain )

Parameters

User

User name to be impersonated It must be a valid user of current computer or domain.

Password

Password to logon

Domain

Computer name or domain name to logon, null indicates local user.

Return Value

If this method succeeds, the return value is zero. If it fails, the return value is non-zero.

Remarks

This method impersonates another user to run this object on current computer or domain. Normally, ASP/ASP.NET applications run under the security context of IUSER_MACHINENAME user, this user doesn't have enough permission to access all files on server. Therefore, many file operations would be failed in ASP/ASP.NET applications such as ExportFile, SaveAttachment, ImportFile and so on. ImpersonateUser method provides a way to run your ASP/ASP.NET applications under administrator or any other user so that POPMSG object has enough permission to access files.

Usage Example

[ASP/VBScript]
Dim oStore
Dim user, password

oStore = Server.CreateObject("ANPOP.MSGSTORE")
user = "administrator"
password = "ad1234"

If oStore.ImpersonateUser( user, password, "" ) = 0 Then 'logon this user
  Response.Write "Impersonate user succeeded"
Else
  Response.Write "Impersonate user failed"
End If

oStore.RevertToSelf 'log off this user and run oMsg with original user
[ASP.NET/Visual Basic]
Dim oStore As ANPOPLib.MSGSTOREClass()
oStore = Server.CreateObject("ANPOP.MSGSTORE")

Dim user, password As String
user = "administrator"
password = "ad1234"

If oStore.ImpersonateUser( user, password, vbNullString ) = 0 Then 'logon this user
  Response.Write( "Impersonate user succeeded" )
Else
  Response.Write( "Impersonate user failed" )
End If

oStore.RevertToSelf() 'log off this user and run oMsg with original user
[ASP.NET/C#]
ANPOPLib.MSGSTOREClass oStore = 
             (ANPOPLib.MSGSTOREClass)Server.CreateObject("ANPOP.MSGSTORE");
string user = "administrator", password = "ad1234";

if( oStore.ImpersonateUser( user, password, null ) == 0 ) //logon this user
  Response.Write( "Impersonate user succeeded" );
else
  Response.Write( "Impersonate user failed" );
  
oStore.RevertToSelf(); //log off this user and run oMsg with original user

See Also

RevertToSelf Method


2001-2007 © Copyright AdminSystem Software Limited. All rights reserved.