I have some code from the 4guysfromrolla website which gives a tutorial on logging in as another user with admin credentials.
I have most of it working but i'm having some trouble translating this part of the code from VB to C#. The part I'm having trouble translating is the first if
statement.
If Page.User.Identity IsNot Nothing AndAlso TypeOf Page.User.Identity Is FormsIdentity Then
Dim ident As FormsIdentity = CType(Page.User.Identity, FormsIdentity)
Dim ticket As FormsAuthenticationTicket = ident.Ticket
Dim AdminUserName As String = ticket.UserData
If Not String.IsNullOrEmpty(AdminUserName) Then
'An Admin user is logged on as another user...
'The variable AdminUserName returns the Admin user's name
'To get the currently logged on user's name, use Page.User.Identity.Name
Else
'The user logged on directly (the typical scenario)
End If
End If
I would be most grateful if someone could help me translate this! This is the part where the page detects if the user is indeed an admin logging in as another user, so that I can programmatically display a panel with a reminder of that.
From http://converter.telerik.com/:
if (Page.User.Identity != null && Page.User.Identity is FormsIdentity) {
FormsIdentity ident = (FormsIdentity)Page.User.Identity;
FormsAuthenticationTicket ticket = ident.Ticket;
string AdminUserName = ticket.UserData;
if (!string.IsNullOrEmpty(AdminUserName)) {
//An Admin user is logged on as another user...
//The variable AdminUserName returns the Admin user's name
//To get the currently logged on user's name, use Page.User.Identity.Name
} else {
//The user logged on directly (the typical scenario)
}
}