Membership.GetUser 方法

定义

从数据源获取成员资格用户的信息。Gets the information for a membership user from the data source.

重载

GetUser(String, Boolean)

获取数据源中指定成员资格用户的信息。Gets the information from the data source for the specified membership user. 更新用户(如果指定)的最近一次活动的日期/时间戳。Updates the last-activity date/time stamp for the user, if specified.

GetUser(Object, Boolean)

从数据源获取与指定的唯一标识符关联的成员资格用户信息。Gets the information from the data source for the membership user associated with the specified unique identifier. 更新用户(如果指定)的最近一次活动的日期/时间戳。Updates the last-activity date/time stamp for the user, if specified.

GetUser(String)

获取数据源中指定成员资格用户的信息。Gets the information from the data source for the specified membership user.

GetUser(Boolean)

从数据源获取当前已登录的成员资格用户的信息。Gets the information from the data source for the current logged-on membership user. 为当前已登录的成员资格用户(如果被指定)更新最后一次活动的日期/时间戳。Updates the last-activity date/time stamp for the current logged-on membership user, if specified.

GetUser()

从数据源获取信息并为当前已登录的成员资格用户更新最后一次活动日期/时间戳。Gets the information from the data source and updates the last-activity date/time stamp for the current logged-on membership user.

GetUser(Object)

从数据源获取与指定的唯一标识符关联的成员资格用户信息。Gets the information from the data source for the membership user associated with the specified unique identifier.

GetUser(String, Boolean)

获取数据源中指定成员资格用户的信息。Gets the information from the data source for the specified membership user. 更新用户(如果指定)的最近一次活动的日期/时间戳。Updates the last-activity date/time stamp for the user, if specified.

public:
 static System::Web::Security::MembershipUser ^ GetUser(System::String ^ username, bool userIsOnline);
public static System.Web.Security.MembershipUser GetUser (string username, bool userIsOnline);
static member GetUser : string * bool -> System.Web.Security.MembershipUser
Public Shared Function GetUser (username As String, userIsOnline As Boolean) As MembershipUser

参数

username
String

要检索的用户的名称。The name of the user to retrieve.

userIsOnline
Boolean

如果为 true,则更新指定用户的最近活动日期/时间戳。If true, updates the last-activity date/time stamp for the specified user.

返回

一个 MembershipUser 对象,它表示指定的用户。A MembershipUser object representing the specified user. 如果 username 参数并不对应于现有的用户,则此方法返回 nullIf the username parameter does not correspond to an existing user, this method returns null.

异常

username 包含一个逗号 (,)。username contains a comma (,).

usernamenullusername is null.

示例

下面的代码示例检索指定用户名的密码,并将其发送到指定用户的电子邮件地址。The following code example retrieves the password for a specified user name and sends it to the email address for the specified user. GetUser 的调用指定不更新用户的最后一个活动的日期/时间戳。The call to GetUser specifies that the last-activity date/time stamp for the user not be updated.

<%@ Page Language="C#" %>
<%@ Import Namespace="System.Web.Security" %>
<%@ Import Namespace="System.Net.Mail" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

public void Page_Load(object sender, EventArgs args)
{
  if (!Membership.EnablePasswordRetrieval)
  {
    FormsAuthentication.RedirectToLoginPage();
  }

  Msg.Text = "";

  if (!IsPostBack)
  {
    Msg.Text = "Please enter a user name.";
  }
  else
  {
    VerifyUsername();
  }
}


public void VerifyUsername()
{
    MembershipUser user = Membership.GetUser(UsernameTextBox.Text, false);

    if (user == null)
    {
      Msg.Text = "The user name " + Server.HtmlEncode(UsernameTextBox.Text) + " was not found. Please check the value and re-enter.";

      QuestionLabel.Text = "";
      QuestionLabel.Enabled = false;
      AnswerTextBox.Enabled = false;
      EmailPasswordButton.Enabled = false;
    }
    else
    {
      QuestionLabel.Text = user.PasswordQuestion;
      QuestionLabel.Enabled = true;
      AnswerTextBox.Enabled = true;
      EmailPasswordButton.Enabled = true;
    }
}


public void EmailPassword_OnClick(object sender, EventArgs args)
{
  // Note: Returning a password in clear text using email is not recommended for
  // sites that require a high level of security.

  try
  {
    string password = Membership.Provider.GetPassword(UsernameTextBox.Text, AnswerTextBox.Text);
    MembershipUser u = Membership.GetUser(UsernameTextBox.Text);
    EmailPassword(u.Email, password);
    Msg.Text = "Your password was sent via email.";
  }
  catch (MembershipPasswordException e)
  {
    Msg.Text = "The password answer is incorrect. Please check the value and try again.";
  }
  catch (System.Configuration.Provider.ProviderException e)
  {
    Msg.Text = "An error occurred retrieving your password. Please check your values " +
               "and try again.";
  }
}


private void EmailPassword(string email, string password)
{
  try
  {
    MailMessage Message = new MailMessage("administrator", email);
    Message.Subject = "Your Password";
    Message.Body = "Your password is: " + Server.HtmlEncode(password);

    SmtpClient SmtpMail = new SmtpClient("SMTPSERVER");
    SmtpMail.Send(Message);
  }
  catch 
  {
    Msg.Text = "An exception occurred while sending your password. Please try again.";
  }
}

</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Sample: Retrieve Password</title>
</head>
<body>

<form id="form1" runat="server">
  <h3>Retrieve Password</h3>

  <asp:Label id="Msg" runat="server" ForeColor="maroon" /><br />

  Username: <asp:Textbox id="UsernameTextBox" Columns="30" runat="server" AutoPostBack="true" />
            <asp:RequiredFieldValidator id="UsernameRequiredValidator" runat="server"
                                        ControlToValidate="UsernameTextBox" ForeColor="red"
                                        Display="Static" ErrorMessage="Required" /><br />

  Password Question: <b><asp:Label id="QuestionLabel" runat="server" /></b><br />

  Answer: <asp:TextBox id="AnswerTextBox" Columns="60" runat="server" Enabled="false" />
          <asp:RequiredFieldValidator id="AnswerRequiredValidator" runat="server"
                                      ControlToValidate="AnswerTextBox" ForeColor="red"
                                      Display="Static" ErrorMessage="Required" Enabled="false" /><br />

  <asp:Button id="EmailPasswordButton" Text="Email My Password" 
              OnClick="EmailPassword_OnClick" runat="server" Enabled="false" />

</form>

</body>
</html>

<%@ Page Language="VB" %>

<%@ Import Namespace="System.Web.Security" %>
<%@ Import Namespace="System.Net.Mail" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

  Public Sub Page_Load(ByVal sender As Object, ByVal args As EventArgs)

    If Not Membership.EnablePasswordRetrieval Then
      FormsAuthentication.RedirectToLoginPage()
    End If

    Msg.Text = ""

    If Not IsPostBack Then
      Msg.Text = "Please enter a user name."
    Else
      VerifyUsername()
    End If

  End Sub


  Private Sub VerifyUsername()

    Dim user As MembershipUser = Membership.GetUser(UsernameTextBox.Text, False)

    If user Is Nothing Then
      Msg.Text = "The user name " & Server.HtmlEncode(UsernameTextBox.Text) & " was not found. Please check the value and re-enter."

      QuestionLabel.Text = ""
      QuestionLabel.Enabled = False
      AnswerTextBox.Enabled = False
      EmailPasswordButton.Enabled = False
    Else
      QuestionLabel.Text = user.PasswordQuestion
      QuestionLabel.Enabled = True
      AnswerTextBox.Enabled = True
      EmailPasswordButton.Enabled = True
    End If

  End Sub


  Public Sub EmailPassword_OnClick(ByVal sender As Object, ByVal args As EventArgs)

    ' Note: Returning a password in clear text using email is not recommended for
    ' sites that require a high level of security.

    Try
      Dim password As String = Membership.Provider.GetPassword(UsernameTextBox.Text, AnswerTextBox.Text)
      Dim u As MembershipUser = Membership.GetUser(UsernameTextBox.Text)
      EmailPassword(u.Email, password)
      Msg.Text = "Your password was sent via email."
    Catch e As MembershipPasswordException
      Msg.Text = "The password answer is incorrect. Please check the value and try again."
    Catch e As System.Configuration.Provider.ProviderException
      Msg.Text = "An error occurred retrieving your password. Please check your values " & _
                 "and try again."
    End Try

  End Sub


  Private Sub EmailPassword(ByVal email As String, ByVal password As String)

    Try
      Dim Message As MailMessage = New MailMessage("administrator", email)
      Message.Subject = "Your Password"
      Message.Body = "Your password is: " & Server.HtmlEncode(password)
      
      Dim SmtpMail As SmtpClient = New SmtpClient("SMTPSERVER")
      SmtpMail.Send(Message)
    Catch
      Msg.Text = "An exception occurred while sending your password. Please try again."
    End Try

  End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
  <title>Sample: Retrieve Password</title>
</head>
<body>
  <form id="form1" runat="server">
    <h3>
      Retrieve Password</h3>
    <asp:Label ID="Msg" runat="server" ForeColor="maroon" /><br />
    Username:
    <asp:TextBox ID="UsernameTextBox" Columns="30" runat="server" AutoPostBack="True" />
    <asp:RequiredFieldValidator ID="UsernameRequiredValidator" runat="server" ControlToValidate="UsernameTextBox"
      ForeColor="red" Display="Static" ErrorMessage="Required" /><br />
    Password Question: <b>
      <asp:Label ID="QuestionLabel" runat="server" /></b><br />
    Answer:
    <asp:TextBox ID="AnswerTextBox" Columns="60" runat="server" Enabled="False" />
    <asp:RequiredFieldValidator ID="AnswerRequiredValidator" runat="server" ControlToValidate="AnswerTextBox"
      ForeColor="red" Display="Static" ErrorMessage="Required" Enabled="False" /><br />
    <asp:Button ID="EmailPasswordButton" Text="Email My Password" OnClick="EmailPassword_OnClick"
      runat="server" Enabled="False" />
  </form>
</body>
</html>

注解

GetUser 方法从数据源检索用户信息,并创建用返回的数据填充的 MembershipUser 对象。The GetUser method retrieves the user information from the data source and creates a MembershipUser object populated with the returned data.

如果使用不采用 username 参数的 GetUser 重载之一,GetUser 将返回当前登录的成员资格用户的信息。If you use one of the GetUser overloads that does not take a username parameter, GetUser returns the information for the current logged-on membership user. 当前登录的成员资格用户由当前 HttpContext中用户的 Name 标识。The current logged-on membership user is identified by the Name of the user in the current HttpContext.

您还可以指定是否希望 GetUser 为用 userIsOnline 参数检索的用户更新上一次活动的日期/时间戳。You can also specify whether you want GetUser to update the last-activity date/time stamp for the user being retrieved with the userIsOnline parameter. 对于不采用 userIsOnline 参数的 GetUser 重载,Membership.GetUser 隐式更新用户的最近一次活动的日期/时间戳。Of the GetUser overloads that do not take a userIsOnline parameter, Membership.GetUser implicitly updates the last-activity date/time stamp for the user. Membership.GetUserGetUser 不是这样。Membership.GetUser and GetUser do not.

另请参阅

GetUser(Object, Boolean)

从数据源获取与指定的唯一标识符关联的成员资格用户信息。Gets the information from the data source for the membership user associated with the specified unique identifier. 更新用户(如果指定)的最近一次活动的日期/时间戳。Updates the last-activity date/time stamp for the user, if specified.

public:
 static System::Web::Security::MembershipUser ^ GetUser(System::Object ^ providerUserKey, bool userIsOnline);
public static System.Web.Security.MembershipUser GetUser (object providerUserKey, bool userIsOnline);
static member GetUser : obj * bool -> System.Web.Security.MembershipUser
Public Shared Function GetUser (providerUserKey As Object, userIsOnline As Boolean) As MembershipUser

参数

providerUserKey
Object

用户的成员资格数据源中的唯一用户标识符。The unique user identifier from the membership data source for the user.

userIsOnline
Boolean

如果为 true,则更新指定用户的最近活动日期/时间戳。If true, updates the last-activity date/time stamp for the specified user.

返回

一个 MembershipUser 对象,它表示与指定的唯一标识符关联的用户。A MembershipUser object representing the user associated with the specified unique identifier.

异常

providerUserKeynullproviderUserKey is null.

注解

GetUser 方法从数据源检索用户信息,并创建用返回的数据填充的 MembershipUser 对象。The GetUser method retrieves the user information from the data source and creates a MembershipUser object populated with the returned data. 用户通过 providerUserKey 参数中指定的数据源中的唯一标识符进行标识。The user is identified with the unique identifier from the data source specified in the providerUserKey parameter.

另请参阅

GetUser(String)

获取数据源中指定成员资格用户的信息。Gets the information from the data source for the specified membership user.

public:
 static System::Web::Security::MembershipUser ^ GetUser(System::String ^ username);
public static System.Web.Security.MembershipUser GetUser (string username);
static member GetUser : string -> System.Web.Security.MembershipUser
Public Shared Function GetUser (username As String) As MembershipUser

参数

username
String

要检索的用户的名称。The name of the user to retrieve.

返回

一个 MembershipUser 对象,它表示指定的用户。A MembershipUser object representing the specified user. 如果 username 参数并不对应于现有的用户,则此方法返回 nullIf the username parameter does not correspond to an existing user, this method returns null.

异常

username 包含一个逗号 (,)。username contains a comma (,).

usernamenullusername is null.

示例

下面的代码示例使用 GetUser 方法返回当前登录用户的 MembershipUser 对象,并更新该用户的电子邮件地址。The following code example uses the GetUser method to return a MembershipUser object for the current logged-on user and updates the email address for the user.

<%@ Page Language="C#" %>
<%@ Import Namespace="System.Web.Security" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

MembershipUser u;

public void Page_Load(object sender, EventArgs args)
{
  u = Membership.GetUser(User.Identity.Name);

  if (!IsPostBack)
  {
    EmailTextBox.Text = u.Email; 
  }
}

public void UpdateEmailButton_OnClick(object sender, EventArgs args)
{
  try
  {
    u.Email = EmailTextBox.Text;

    Membership.UpdateUser(u);
  
    Msg.Text = "User email updated.";
  }
  catch (System.Configuration.Provider.ProviderException e)
  {
    Msg.Text = e.Message;
  }
}

</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Sample: Update User E-Mail</title>
</head>
<body>

<form id="form1" runat="server">
  <h3>Update E-Mail Address for <%=User.Identity.Name%></h3>

  <asp:Label id="Msg" ForeColor="maroon" runat="server" /><br />

  <table cellpadding="3" border="0">
    <tr>
      <td>Email Address:</td>
      <td><asp:TextBox id="EmailTextBox" MaxLength="128" Columns="30" runat="server" /></td>
      <td><asp:RequiredFieldValidator id="EmailRequiredValidator" runat="server"
                                    ControlToValidate="EmailTextBox" ForeColor="red"
                                    Display="Static" ErrorMessage="Required" /></td>
    </tr>
    <tr>
      <td></td>
      <td><asp:Button id="UpdateEmailButton" 
                      Text="Update Email" 
                      OnClick="UpdateEmailButton_OnClick" 
                      runat="server" /></td>
    </tr>
  </table>
</form>

</body>
</html>
<%@ Page Language="vb" %>
<%@ Import Namespace="System.Web.Security" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

Dim u As MembershipUser

Public Sub Page_Load(sender As Object, args As EventArgs)

  u = Membership.GetUser(User.Identity.Name)

  If Not IsPostBack Then EmailTextBox.Text = u.Email

End Sub

Public Sub UpdateEmailButton_OnClick(sender As Object, args As EventArgs)

  Try
    u.Email = EmailTextBox.Text

    Membership.UpdateUser(u)
  
    Msg.Text = "User email updated."
  Catch e As System.Configuration.Provider.ProviderException
    Msg.Text = e.Message
  End Try

End Sub

</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Sample: Update User E-Mail</title>
</head>
<body>

<form id="form1" runat="server">
  <h3>Update E-Mail Address for <%=User.Identity.Name%></h3>

  <asp:Label id="Msg" ForeColor="maroon" runat="server" /><br />

  <table cellpadding="3" border="0">
    <tr>
      <td>Email Address:</td>
      <td><asp:TextBox id="EmailTextBox" MaxLength="128" Columns="30" runat="server" /></td>
      <td><asp:RequiredFieldValidator id="EmailRequiredValidator" runat="server"
                                    ControlToValidate="EmailTextBox" ForeColor="red"
                                    Display="Static" ErrorMessage="Required" /></td>
    </tr>
    <tr>
      <td></td>
      <td><asp:Button id="UpdateEmailButton" 
                      Text="Update Email" 
                      OnClick="UpdateEmailButton_OnClick" 
                      runat="server" /></td>
    </tr>
  </table>
</form>

</body>
</html>

注解

GetUser 方法从数据源检索用户信息,并创建用返回的数据填充的 MembershipUser 对象。The GetUser method retrieves the user information from the data source and creates a MembershipUser object populated with the returned data. 如果使用不采用 username 参数的 GetUser 重载之一,GetUser 将返回当前登录的成员资格用户的信息。If you use one of the GetUser overloads that does not take a username parameter, GetUser returns the information for the current logged-on membership user. 当前登录的成员资格用户由当前 HttpContext中用户的 Name 标识。The current logged-on membership user is identified by the Name of the user in the current HttpContext.

您还可以指定是否希望 GetUser 为用 userIsOnline 参数检索的用户更新上一次活动的日期/时间戳。You can also specify whether you want GetUser to update the last-activity date/time stamp for the user being retrieved with the userIsOnline parameter. 对于不采用 userIsOnline 参数的 GetUser 重载,Membership.GetUser 隐式更新用户的最近一次活动的日期/时间戳。Of the GetUser overloads that do not take a userIsOnline parameter, Membership.GetUser implicitly updates the last-activity date/time stamp for the user. Membership.GetUserGetUser 不是这样。Membership.GetUser and GetUser do not.

另请参阅

GetUser(Boolean)

从数据源获取当前已登录的成员资格用户的信息。Gets the information from the data source for the current logged-on membership user. 为当前已登录的成员资格用户(如果被指定)更新最后一次活动的日期/时间戳。Updates the last-activity date/time stamp for the current logged-on membership user, if specified.

public:
 static System::Web::Security::MembershipUser ^ GetUser(bool userIsOnline);
public static System.Web.Security.MembershipUser GetUser (bool userIsOnline);
static member GetUser : bool -> System.Web.Security.MembershipUser
Public Shared Function GetUser (userIsOnline As Boolean) As MembershipUser

参数

userIsOnline
Boolean

如果为 true,则更新指定用户的最近活动日期/时间戳。If true, updates the last-activity date/time stamp for the specified user.

返回

一个 MembershipUser 对象,表示当前已登录的用户。A MembershipUser object representing the current logged-on user.

异常

当前没有成员资格用户登陆。No membership user is currently logged in.

示例

下面的代码示例在 ASP.NET 页中显示当前登录的成员资格用户的用户名,而不更新用户的上一次活动日期/时间戳。The following code example displays the user name for the current logged-on membership user in the ASP.NET page without updating the last-activity date/time stamp for the user.

<%@ Page Language="C#" %>
<%@ Import Namespace="System.Web.Security" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

MembershipUser currentUser;

public void Page_Load()
{
  currentUser = Membership.GetUser(false);
}

</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Home Page</title>
</head>
<body>

<form id="form1" runat="server">
Welcome <b><%=currentUser.UserName%></b>. 
</form>

</body>
</html>
<%@ Page Language="VB" %>
<%@ Import Namespace="System.Web.Security" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

Dim currentUser As MembershipUser

Public Sub Page_Load()
  currentUser = Membership.GetUser(False)
End Sub

</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Home Page</title>
</head>
<body>

<form id="form1" runat="server">
Welcome <b><%=currentUser.UserName%></b>.
</form>

</body>
</html>

注解

GetUser 方法从数据源检索用户信息,并创建用返回的数据填充的 MembershipUser 对象。The GetUser method retrieves the user information from the data source and creates a MembershipUser object populated with the returned data. 如果使用不采用 username 参数的 GetUser 重载之一,GetUser 将返回当前登录的成员资格用户的信息。If you use one of the GetUser overloads that does not take a username parameter, GetUser returns the information for the current logged-on membership user. 当前登录的成员资格用户由当前 HttpContext中用户的 Name 标识。The current logged-on membership user is identified by the Name of the user in the current HttpContext.

您还可以指定是否要 GetUser 更新使用 userIsOnline 参数检索的用户的最近一次活动的日期/时间戳。You can also specify whether you want GetUser to update the last-activity date/time stamp for the user being retrieved using the userIsOnline parameter. 对于不采用 userIsOnline 参数的 GetUser 重载,GetUser() 隐式更新用户的最近一次活动的日期/时间戳。Of the GetUser overloads that do not take a userIsOnline parameter, GetUser() implicitly updates the last-activity date/time stamp for the user. GetUser(System.String)GetUser(System.Object) 不是这样。GetUser(System.String) and GetUser(System.Object) do not.

另请参阅

GetUser()

从数据源获取信息并为当前已登录的成员资格用户更新最后一次活动日期/时间戳。Gets the information from the data source and updates the last-activity date/time stamp for the current logged-on membership user.

public:
 static System::Web::Security::MembershipUser ^ GetUser();
public static System.Web.Security.MembershipUser GetUser ();
static member GetUser : unit -> System.Web.Security.MembershipUser
Public Shared Function GetUser () As MembershipUser

返回

一个 MembershipUser 对象,表示当前已登录的用户。A MembershipUser object representing the current logged-on user.

异常

当前没有成员资格用户登陆。No membership user is currently logged in.

示例

下面的代码示例将更新当前已登录的成员资格用户的最近一次活动的日期/时间戳,并在 ASP.NET 页中显示该用户名。The following code example updates the last-activity date/time stamp for the current logged-on membership user and displays the user name in the ASP.NET page.

<%@ Page Language="C#" %>
<%@ Import Namespace="System.Web.Security" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

MembershipUser currentUser;

public void Page_Load()
{
  currentUser = Membership.GetUser();
}

</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Home Page</title>
</head>
<body>

<form id="form1" runat="server">
Welcome <b><%=currentUser.UserName%></b>. 
</form>

</body>
</html>
<%@ Page Language="VB" %>
<%@ Import Namespace="System.Web.Security" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

Dim currentUser As MembershipUser

Public Sub Page_Load()
  currentUser = Membership.GetUser()
End Sub

</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Home Page</title>
</head>
<body>

<form id="form1" runat="server">
Welcome <b><%=currentUser.UserName%></b>.
</form>

</body>
</html>

注解

GetUser() 从数据源检索用户信息,并创建用返回的数据填充的 MembershipUser 对象。GetUser() retrieves the user information from the data source and creates a MembershipUser object populated with the returned data. 如果使用不采用 username 参数的 GetUser 重载之一,GetUser 将返回当前登录的成员资格用户的信息。If you use one of the GetUser overloads that does not take a username parameter, GetUser returns the information for the current logged-on membership user. 当前登录的成员资格用户由当前 HttpContext中用户的 Name 标识。The current logged-on membership user is identified by the Name of the user in the current HttpContext.

您还可以指定是否要 GetUser 更新使用 userIsOnline 参数检索的用户的最近一次活动的日期/时间戳。You can also specify whether you want GetUser to update the last-activity date/time stamp for the user being retrieved using the userIsOnline parameter. 对于不采用 userIsOnline 参数的 GetUser 重载,GetUser() 隐式更新用户的最近一次活动的日期/时间戳。Of the GetUser overloads that do not take a userIsOnline parameter, GetUser() implicitly updates the last-activity date/time stamp for the user. GetUser(System.String)GetUser(System.Object) 不是这样。GetUser(System.String) and GetUser(System.Object) do not.

另请参阅

GetUser(Object)

从数据源获取与指定的唯一标识符关联的成员资格用户信息。Gets the information from the data source for the membership user associated with the specified unique identifier.

public:
 static System::Web::Security::MembershipUser ^ GetUser(System::Object ^ providerUserKey);
public static System.Web.Security.MembershipUser GetUser (object providerUserKey);
static member GetUser : obj -> System.Web.Security.MembershipUser
Public Shared Function GetUser (providerUserKey As Object) As MembershipUser

参数

providerUserKey
Object

用户的成员资格数据源中的唯一用户标识符。The unique user identifier from the membership data source for the user.

返回

一个 MembershipUser 对象,它表示与指定的唯一标识符关联的用户。A MembershipUser object representing the user associated with the specified unique identifier.

异常

providerUserKeynullproviderUserKey is null.

注解

GetUser 方法从数据源检索用户信息,并创建用返回的数据填充的 MembershipUser 对象。The GetUser method retrieves the user information from the data source and creates a MembershipUser object populated with the returned data. 用户使用从使用 providerUserKey 参数指定的数据源中的唯一标识符进行标识。The user is identified using the unique identifier from the data source specified using the providerUserKey parameter.

您还可以指定是否希望 GetUser 为用 userIsOnline 参数检索的用户更新上一次活动的日期/时间戳。You can also specify whether you want GetUser to update the last-activity date/time stamp for the user being retrieved with the userIsOnline parameter. 对于不采用 userIsOnline 参数的 GetUser 重载,GetUser() 隐式更新用户的最近一次活动的日期/时间戳。Of the GetUser overloads that do not take a userIsOnline parameter, GetUser() implicitly updates the last-activity date/time stamp for the user. GetUser(System.String)GetUser(System.Object)GetUser(System.String) and GetUser(System.Object) do not

另请参阅

适用于