I’m sure this is trivial, but why isn’t the Windows Authentication user printing in my ASP.NET page inline?
Code behind function:
public string GetCurrentUserWindowsLogin()
{
string windowsLogin = Page.User.Identity.Name;
int hasDomain = windowsLogin.IndexOf(@"\");
if (hasDomain > 0)
{
windowsLogin = windowsLogin.Remove(0, hasDomain + 1);
}
return windowsLogin;
}
Inline code:
<div class="loginDisplay">[ <%#GetCurrentUserWindowsLogin() %> ]</div>
The
<%#... %>is used for Binding Expressions likeEvalandBind.So if you call
Page.DataBind()inpage_loadit should work.Another way that should work is to use code render blocks which run normal code:
<% GetCurrentUserWindowsLogin() %>or the
<%= %>construct used for small chunks of information:<%= GetCurrentUserWindowsLogin() %>