-2

Please tell me how to get current user and how to display loggedin users name in Asp.net using C#. Please tell me ASAP

4

2 回答 2

1
var username = HttpContext.Current.User.Identity.Name;
于 2012-04-25T16:13:38.577 回答
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>
于 2012-04-25T16:15:52.540 回答