Membership.FindUsersByEmail 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
獲得一組會員用戶,電子郵件地址包含指定的電子郵件地址以匹配。
多載
| 名稱 | Description |
|---|---|
| FindUsersByEmail(String, Int32, Int32, Int32) |
會取得一組會員用戶,在一頁資料中,電子郵件地址包含指定的電子郵件地址以匹配。 |
| FindUsersByEmail(String) |
獲得一組會員用戶,電子郵件地址包含指定的電子郵件地址以匹配。 |
FindUsersByEmail(String, Int32, Int32, Int32)
會取得一組會員用戶,在一頁資料中,電子郵件地址包含指定的電子郵件地址以匹配。
public:
static System::Web::Security::MembershipUserCollection ^ FindUsersByEmail(System::String ^ emailToMatch, int pageIndex, int pageSize, [Runtime::InteropServices::Out] int % totalRecords);
public static System.Web.Security.MembershipUserCollection FindUsersByEmail(string emailToMatch, int pageIndex, int pageSize, out int totalRecords);
static member FindUsersByEmail : string * int * int * int -> System.Web.Security.MembershipUserCollection
Public Shared Function FindUsersByEmail (emailToMatch As String, pageIndex As Integer, pageSize As Integer, ByRef totalRecords As Integer) As MembershipUserCollection
參數
- emailToMatch
- String
要搜尋的電子郵件地址。
- pageIndex
- Int32
結果頁面的索引將返回。
pageIndex 以零為起始。
- pageSize
- Int32
結果頁面的大小。
- totalRecords
- Int32
配對的總數。
傳回
A MembershipUserCollection 包含從指定的pageSize頁面開始的物件頁面MembershipUserpageIndex。
例外狀況
範例
以下程式碼範例使用此 FindUsersByEmail 方法,根據使用者輸入從會員資料庫中擷取會員使用者資訊,並以頁面資料形式呈現結果。
Important
此範例包含一個接受使用者輸入的文字框,這可能構成安全威脅。 預設情況下,ASP.NET 網頁會驗證使用者輸入中不包含腳本或 HTML 元素。 欲了解更多資訊,請參閱 腳本漏洞概述。
<%@ 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">
int pageSize = 5;
int totalUsers;
int totalPages;
int currentPage = 1;
private void GetUsers()
{
UserGrid.DataSource = Membership.FindUsersByEmail(EmailTextBox.Text,
currentPage - 1, pageSize, out totalUsers);
totalPages = ((totalUsers - 1) / pageSize) + 1;
// Ensure that we do not navigate past the last page of users.
if (currentPage > totalPages)
{
currentPage = totalPages;
GetUsers();
return;
}
UserGrid.DataBind();
CurrentPageLabel.Text = currentPage.ToString();
TotalPagesLabel.Text = totalPages.ToString();
if (currentPage == totalPages)
NextButton.Visible = false;
else
NextButton.Visible = true;
if (currentPage == 1)
PreviousButton.Visible = false;
else
PreviousButton.Visible = true;
if (totalUsers <= 0)
NavigationPanel.Visible = false;
else
NavigationPanel.Visible = true;
}
public void NextButton_OnClick(object sender, EventArgs args)
{
currentPage = Convert.ToInt32(CurrentPageLabel.Text);
currentPage++;
GetUsers();
}
public void PreviousButton_OnClick(object sender, EventArgs args)
{
currentPage = Convert.ToInt32(CurrentPageLabel.Text);
currentPage--;
GetUsers();
}
public void GoButton_OnClick(object sender, EventArgs args)
{
currentPage = 1;
GetUsers();
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Sample: Find Users by Email</title>
</head>
<body>
<form id="form1" runat="server">
<h3>User List</h3>
Email address to Search for:
<asp:TextBox id="EmailTextBox" runat="server" />
<asp:Button id="GoButton" Text=" Go " OnClick="GoButton_OnClick" runat="server" /><br />
<asp:Panel id="NavigationPanel" Visible="false" runat="server">
<table border="0" cellpadding="3" cellspacing="3">
<tr>
<td style="width:100">Page <asp:Label id="CurrentPageLabel" runat="server" />
of <asp:Label id="TotalPagesLabel" runat="server" /></td>
<td style="width:60"><asp:LinkButton id="PreviousButton" Text="< Prev"
OnClick="PreviousButton_OnClick" runat="server" /></td>
<td style="width:60"><asp:LinkButton id="NextButton" Text="Next >"
OnClick="NextButton_OnClick" runat="server" /></td>
</tr>
</table>
</asp:Panel>
<asp:DataGrid id="UserGrid" runat="server"
CellPadding="2" CellSpacing="1"
Gridlines="Both">
<HeaderStyle BackColor="darkblue" ForeColor="white" />
</asp:DataGrid>
</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 pageSize As Integer = 5
Dim totalUsers As Integer
Dim totalPages As Integer
Dim currentPage As Integer = 1
Private Sub GetUsers()
UserGrid.DataSource = Membership.FindUsersByEmail(EmailTextBox.Text, _
currentPage - 1, pageSize, totalUsers)
totalPages = ((totalUsers - 1) \ pageSize) + 1
' Ensure that we do not navigate past the last page of users.
If currentPage > totalPages Then
currentPage = totalPages
GetUsers()
Return
End If
UserGrid.DataBind()
CurrentPageLabel.Text = currentPage.ToString()
TotalPagesLabel.Text = totalPages.ToString()
If currentPage = totalPages Then
NextButton.Visible = False
Else
NextButton.Visible = True
End If
If currentPage = 1 Then
PreviousButton.Visible = False
Else
PreviousButton.Visible = True
End If
If totalUsers <= 0 Then
NavigationPanel.Visible = False
Else
NavigationPanel.Visible = True
End If
End Sub
Public Sub NextButton_OnClick(sender As Object, args As EventArgs)
currentPage = Convert.ToInt32(CurrentPageLabel.Text)
currentPage += 1
GetUsers()
End Sub
Public Sub PreviousButton_OnClick(sender As Object, args As EventArgs)
currentPage = Convert.ToInt32(CurrentPageLabel.Text)
currentPage -= 1
GetUsers()
End Sub
Public Sub GoButton_OnClick(sender As Object, args As EventArgs)
currentPage = 1
GetUsers()
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Sample: Find Users by Email</title>
</head>
<body>
<form id="form1" runat="server">
<h3>User List</h3>
Email address to Search for:
<asp:TextBox id="EmailTextBox" runat="server" />
<asp:Button id="GoButton" Text=" Go " OnClick="GoButton_OnClick" runat="server" /><br />
<asp:Panel id="NavigationPanel" Visible="False" runat="server">
<table border="0" cellpadding="3" cellspacing="3">
<tr>
<td style="width:100">Page <asp:Label id="CurrentPageLabel" runat="server" />
of <asp:Label id="TotalPagesLabel" runat="server" /></td>
<td style="width:60"><asp:LinkButton id="PreviousButton" Text="< Prev"
OnClick="PreviousButton_OnClick" runat="server" /></td>
<td style="width:60"><asp:LinkButton id="NextButton" Text="Next >"
OnClick="NextButton_OnClick" runat="server" /></td>
</tr>
</table>
</asp:Panel>
<asp:DataGrid id="UserGrid" runat="server"
CellPadding="2" CellSpacing="1"
Gridlines="Both">
<HeaderStyle BackColor="darkblue" ForeColor="white" />
</asp:DataGrid>
</form>
</body>
</html>
備註
FindUsersByEmail回傳一份會員用戶名單,電子郵件地址與所提供emailToMatchapplicationName者相符。
該 會 SqlMembershipProvider 利用 LIKE 子句對 emailToMatch 參數進行搜尋。 任何由 LIKE 子句中 SQL Server 支援的萬用字元,都可以用在 emailToMatch 參數值中。
所 FindUsersByEmail 回傳的結果受限 pageIndex 於 和 pageSize 參數。 參數pageSize識別應回傳MembershipUser的最大物件數量MembershipUserCollection。 參數 pageIndex 用來指示要回傳哪一頁結果,其中 0 代表第一頁。 參數 totalRecords 設定 out 為與該值匹配 emailToMatch 的會員用戶總數。 例如,若發現 13 位使用者與 emailToMatch 部分或全部電子郵件地址匹配,且 pageIndex 值為 1,且 a pageSize 為 5,則回傳的郵件 MembershipUserCollection 將包含第六至第十位回傳的使用者。
totalRecords 會設定為13。
參數值中會裁掉 emailToMatch 前置與後置空格。
另請參閱
適用於
FindUsersByEmail(String)
獲得一組會員用戶,電子郵件地址包含指定的電子郵件地址以匹配。
public:
static System::Web::Security::MembershipUserCollection ^ FindUsersByEmail(System::String ^ emailToMatch);
public static System.Web.Security.MembershipUserCollection FindUsersByEmail(string emailToMatch);
static member FindUsersByEmail : string -> System.Web.Security.MembershipUserCollection
Public Shared Function FindUsersByEmail (emailToMatch As String) As MembershipUserCollection
參數
- emailToMatch
- String
要搜尋的電子郵件地址。
傳回
MembershipUserCollection包含所有符合參數emailToMatch的使用者。
參數值中會裁掉 emailToMatch 前置與後置空格。
範例
以下程式碼範例使用此 FindUsersByEmail 方法,根據使用者輸入從會員資料庫中擷取會員使用者資訊,並以頁面資料形式呈現結果。
Important
此範例包含一個接受使用者輸入的文字框,這可能構成安全威脅。 預設情況下,ASP.NET 網頁會驗證使用者輸入中不包含腳本或 HTML 元素。 欲了解更多資訊,請參閱 腳本漏洞概述。
<%@ 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">
public void GoButton_OnClick(object sender, EventArgs args)
{
UserGrid.DataSource = Membership.FindUsersByEmail(EmailTextBox.Text);
UserGrid.DataBind();
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Sample: Find Users by Email</title>
</head>
<body>
<form id="form1" runat="server">
<h3>User List</h3>
Email address to Search for:
<asp:TextBox id="EmailTextBox" runat="server" />
<asp:Button id="GoButton" Text=" Go " OnClick="GoButton_OnClick" runat="server" /><br />
<asp:DataGrid id="UserGrid" runat="server"
CellPadding="2" CellSpacing="1"
Gridlines="Both">
<HeaderStyle BackColor="darkblue" ForeColor="white" />
</asp:DataGrid>
</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">
Public Sub GoButton_OnClick(sender As Object, args As EventArgs)
UserGrid.DataSource = Membership.FindUsersByEmail(EmailTextBox.Text)
UserGrid.DataBind()
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Sample: Find Users by Email</title>
</head>
<body>
<form id="form1" runat="server">
<h3>User List</h3>
Email address to Search for:
<asp:TextBox id="EmailTextBox" runat="server" />
<asp:Button id="GoButton" Text=" Go " OnClick="GoButton_OnClick" runat="server" /><br />
<asp:DataGrid id="UserGrid" runat="server"
CellPadding="2" CellSpacing="1"
Gridlines="Both">
<HeaderStyle BackColor="darkblue" ForeColor="white" />
</asp:DataGrid>
</form>
</body>
</html>
備註
FindUsersByEmail回傳一份會員用戶名單,電子郵件地址與所提供emailToMatchapplicationName者相符。
該 會 SqlMembershipProvider 利用 LIKE 子句對 emailToMatch 參數進行搜尋。 任何由 LIKE 子句中 SQL Server 支援的萬用字元,都可以用在 emailToMatch 參數值中。