请告诉我如何使用C#获取当前用户以及如何在Asp.net中显示登录用户名。请尽快告诉我
答案 0 :(得分:1)
var username = HttpContext.Current.User.Identity.Name;
答案 1 :(得分:1)
您可以在页面上放置http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.loginview.aspx#Y0 Loginview控件
<asp:LoginView ID="LoginView1" Runat="server">
<LoggedInTemplate>
<asp:LoginName ID="LoginName1" Runat="server"
FormatString ="Welcome, {0}" />
<br />
<asp:HyperLink ID="HyperLink1" Runat="server"
NavigateUrl="~/MemberPages/ChangePassword.aspx">
Change Password
</asp:HyperLink>
</LoggedInTemplate>
<AnonymousTemplate>
<asp:Login id="Login1" runat="server"
CreateUserText="Create a new user..."
CreateUserUrl="~/Register.aspx"
PasswordRecoveryUrl="~/Recovery.aspx"
UserNameLabelText="E-mail address:" />
</AnonymousTemplate>
</asp:LoginView>