Log off user who logon with ImpersonateUser method
[Syntax] C++: HRESULT RevertToSelf() Visual Basic: RevertToSelf() C#: void RevertToSelf()
Remarks
This method logs off current impersonated user with ImpersonateUser method. 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.