I'm trying to get the user's name and surname from active directory using the following code:
Default.aspx.cs:
public partial class _Default : Page
{
protected void Page_Load(object sender, EventArgs e)
{
// get the user's name from active dirctory
var user = UserPrincipal.Current;
string firstName = user.GivenName;
string lastName = user.Surname;
}
}
Default.aspx:
<p class="text-center"><strong><% =firstName =lastName %></strong></p>
However, I get an error saying the variables do not exist in the current context.
I have tried putting public in front of the two strings, but then I get an error saying it's an invalid expression term.
Any suggestions would be great, thank you