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 oMsg
Dim user, password
oMsg = Server.CreateObject("ANPOP.POPMSG")
user = "administrator"
password = "ad1234"
If oMsg.ImpersonateUser( user, password, "" ) = 0 Then 'logon this user
Response.Write "Impersonate user succeeded"
Else
Response.Write "Impersonate user failed"
End If
oMsg.RevertToSelf 'log off this user and run oMsg with original user
[ASP.NET/Visual Basic]
Dim oMsg As ANPOPLib.POPMSGClass()
oMsg = Server.CreateObject("ANPOP.POPMSG")
Dim user, password As String
user = "administrator"
password = "ad1234"
If oMsg.ImpersonateUser( user, password, vbNullString ) = 0 Then 'logon this user
Response.Write( "Impersonate user succeeded" )
Else
Response.Write( "Impersonate user failed" )
End If
oMsg.RevertToSelf() 'log off this user and run oMsg with original user
[ASP.NET/C#]
ANPOPLib.POPMSGClass oMsg =
(ANPOPLib.POPMSGClass)Server.CreateObject("ANPOP.POPMSG");
string user = "administrator", password = "ad1234";
if( oMsg.ImpersonateUser( user, password, null ) == 0 ) //logon this user
Response.Write( "Impersonate user succeeded" );
else
Response.Write( "Impersonate user failed" );
oMsg.RevertToSelf(); //log off this user and run oMsg with original user
See Also
2001-2007 © Copyright AdminSystem Software Limited. All rights reserved.