Share via


ProfileManager 클래스

정의

사용자 프로필 데이터와 설정을 관리합니다.

public ref class ProfileManager abstract sealed
public static class ProfileManager
type ProfileManager = class
Public Class ProfileManager
상속
ProfileManager

예제

다음 코드 예제에서는 클래스를 사용 하 여 ProfileManager 비활성 프로필을 관리 하는 ASP.NET 페이지를 보여 줍니다.

중요

이 예제에서는 잠재적 보안 위협을 사용자 입력을 허용 하는 텍스트 상자가 포함 되어 있습니다. 기본적으로 ASP.NET 웹 페이지는 사용자 입력 내용에 스크립트 또는 HTML 요소가 포함되어 있지 않은지 확인합니다. 자세한 내용은 Script Exploits Overview를 참조하세요.

<%@ Page Language="C#" %>
<%@ Import Namespace="System.Web.Profile" %>
<!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 totalProfiles;
int totalPages;
int currentPage = 1;

ProfileAuthenticationOption authOption;
int inactiveDays = 120;
int deletedProfiles = 0;

public void Page_Load()
{
  DeletedMessage.Text = "";

  authOption = GetAuthenticationOption();

  if (!IsPostBack)
  {
    InactiveDaysTextBox.Text = inactiveDays.ToString();

    GetProfiles();
  }
  else
  {
    inactiveDays = Convert.ToInt32(InactiveDaysTextBox.Text);
  }
}

public void ProfileGrid_Delete(object sender, GridViewCommandEventArgs args)
{
  // Retrieve user name selected.

  int index = Convert.ToInt32(args.CommandArgument);

  string username = ProfileGrid.Rows[index].Cells[0].Text;

  ProfileManager.DeleteProfiles(new string[] {username});

  DeletedMessage.Text = "1 profile deleted.";

  // Refresh profile list.

  currentPage = Convert.ToInt32(CurrentPageLabel.Text);
  GetProfiles();
}


private void GetProfiles()
{
  ProfileGrid.DataSource = ProfileManager.GetAllInactiveProfiles(authOption,
                               DateTime.Now.Subtract(new TimeSpan(inactiveDays, 0, 0, 0)),
                               currentPage - 1, pageSize, out totalProfiles);

  TotalProfilesLabel.Text = totalProfiles.ToString();

  totalPages = ((totalProfiles - 1) / pageSize) + 1;

  // Ensure that we do not navigate past the last page of Profiles.

  if (currentPage > totalPages)
  {
    currentPage = totalPages;
    GetProfiles();
    return;
  }

  ProfileGrid.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 (totalProfiles <= 0)
    NavigationPanel.Visible = false;
  else
    NavigationPanel.Visible = true;
}

public void NextButton_OnClick(object sender, EventArgs args)
{
  currentPage = Convert.ToInt32(CurrentPageLabel.Text);
  currentPage++;
  GetProfiles();
}

public void PreviousButton_OnClick(object sender, EventArgs args)
{
  currentPage = Convert.ToInt32(CurrentPageLabel.Text);
  currentPage--;
  GetProfiles();
}

public void ModifyInactiveDaysButton_OnClick(object sender, EventArgs args)
{
  GetProfiles();
}

public void AuthenticationOptionListBox_OnSelectedIndexChanged(object sender, EventArgs args)
{
  authOption = GetAuthenticationOption();
  GetProfiles();
}

private ProfileAuthenticationOption GetAuthenticationOption()
{
  if (AuthenticationOptionListBox.SelectedItem != null)
  {
    switch (AuthenticationOptionListBox.SelectedItem.Value)
    {
      case "Anonymous":
        return ProfileAuthenticationOption.Anonymous;
        break;
      case "Authenticated":
        return ProfileAuthenticationOption.Authenticated;
        break;
      default:
        return ProfileAuthenticationOption.All;
        break;
    }
  }

  return ProfileAuthenticationOption.All;
}

public void DeleteAllInactiveButton_OnClick(object sender, EventArgs args)
{
  deletedProfiles = ProfileManager.DeleteInactiveProfiles(authOption, 
                        DateTime.Now.Subtract(new TimeSpan(inactiveDays, 0, 0 ,0)));
  DeletedMessage.Text = deletedProfiles.ToString() + " profiles deleted.";
  GetProfiles();
}

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

<form id="form1" runat="server">
  <h3>Profile List</h3>

  <table border="0" cellpadding="3" cellspacing="3">
    <tr>
      <td valign="top">Authentication Option</td>
      <td valign="top"><asp:ListBox id="AuthenticationOptionListBox" rows="3" runat="Server"
                                    AutoPostBack="true"
                                    OnSelectedIndexChanged="AuthenticationOptionListBox_OnSelectedIndexChanged">
                         <asp:ListItem value="All" selected="True">All</asp:ListItem>
                         <asp:ListItem value="Authenticated">Authenticated</asp:ListItem>
                         <asp:ListItem value="Anonymous">Anonymous</asp:ListItem>
                       </asp:ListBox>
      </td>
    </tr>
    <tr>
      <td valign="top" style="width:160">
        Number of Days for Profile to be considered "inactive"</td>
      <td valign="top" style="width:200">
        <asp:TextBox id="InactiveDaysTextBox" runat="Server" MaxLength="3" Columns="3" />
        <asp:Button id="ModifyInactiveDaysButton" runat="server" Text="Refresh Results" 
           OnClick="ModifyInactiveDaysButton_OnClick" /><br />
        <asp:Button id="DeleteAllInactiveButton" runat="Server"
           Text="Delete All Inactive Profiles" OnClick="DeleteAllInactiveButton_OnClick" />
      </td>
      <td valign="top">
        <asp:RequiredFieldValidator id="InactiveDaysRequiredValidator" runat="server"
           ControlToValidate="InactiveDaysTextBox" ForeColor="red"
           Display="Static" ErrorMessage="Required" />
        <asp:RegularExpressionValidator id="InactiveDaysValidator" runat="server"
           ControlToValidate="InactiveDaysTextBox" ForeColor="red"
           Display="Static" ValidationExpression="[0-9]*" 
           ErrorMessage="Inactive Days must be a whole number less than 1000 (e.g. 30, 120)" />
     </td>
    </tr>
    <tr>
      <td><asp:Label id="DeletedMessage" runat="server" /></td>
      <td><asp:Label id="TotalProfilesLabel" runat="server" /> inactive profiles found.</td>
    </tr>
  </table>

    <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:GridView id="ProfileGrid" runat="server" AutoGenerateColumns="false"
                OnRowCommand="ProfileGrid_Delete"
                CellPadding="2" CellSpacing="1" Gridlines="None">
    <HeaderStyle BackColor="darkblue" ForeColor="white" />
    <Columns>
      <asp:BoundField HeaderText="User Name" DataField="Username" />
      <asp:BoundField HeaderText="Is Anonymous" DataField="IsAnonymous" />
      <asp:BoundField HeaderText="Last Updated" DataField="LastUpdatedDate" />
      <asp:BoundField HeaderText="Last Activity" DataField="LastActivityDate" />
      <asp:ButtonField HeaderText="Action" Text="Delete" ButtonType="Link" />
    </Columns>
  </asp:GridView>

</form>

</body>
</html>
<%@ Page Language="VB" %>
<%@ Import Namespace="System.Web.Profile" %>
<!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 totalProfiles As Integer 
Dim totalPages As Integer
Dim currentPage As Integer = 1

Dim authOption As ProfileAuthenticationOption
Dim inactiveDays As Integer = 120
Dim deletedProfiles As Integer = 0

Public Sub Page_Load()

  DeletedMessage.Text = ""

  authOption = GetAuthenticationOption()

  If Not IsPostBack Then  
    InactiveDaysTextBox.Text = inactiveDays.ToString()

    GetProfiles()
  Else
    inactiveDays = Convert.ToInt32(InactiveDaysTextBox.Text)
  End If
End Sub

Public Sub ProfileGrid_Delete(sender As Object, args As GridViewCommandEventArgs)
  ' Retrieve user name selected.

  Dim index As Integer = Convert.ToInt32(args.CommandArgument)

  Dim username As String = ProfileGrid.Rows(index).Cells(0).Text

  ProfileManager.DeleteProfiles(New string() {username})

  DeletedMessage.Text = "1 profile deleted."

  ' Refresh profile list.

  currentPage = Convert.ToInt32(CurrentPageLabel.Text)
  GetProfiles()
End Sub


Private Sub GetProfiles()
  ProfileGrid.DataSource = ProfileManager.GetAllInactiveProfiles(authOption, _
                               DateTime.Now.Subtract(New TimeSpan(inactiveDays, 0, 0, 0)), _
                               currentPage - 1, pageSize, totalProfiles)

  TotalProfilesLabel.Text = totalProfiles.ToString()

  totalPages = ((totalProfiles - 1) \ pageSize) + 1

  ' Ensure that we do not navigate past the last page of Profiles.

  If currentPage > totalPages Then  
    currentPage = totalPages
    GetProfiles()
    Return
  End If

  ProfileGrid.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 totalProfiles <= 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
  GetProfiles()
End Sub

Public Sub PreviousButton_OnClick(sender As Object, args As EventArgs)
  currentPage = Convert.ToInt32(CurrentPageLabel.Text)
  currentPage -= 1
  GetProfiles()
End Sub

Public Sub ModifyInactiveDaysButton_OnClick(sender As Object, args As EventArgs)
  GetProfiles()
End Sub

Public Sub AuthenticationOptionListBox_OnSelectedIndexChanged(sender As Object, args As EventArgs)
  authOption = GetAuthenticationOption()
  GetProfiles()
End Sub

Private Function GetAuthenticationOption() As ProfileAuthenticationOption 
  If Not AuthenticationOptionListBox.SelectedItem Is Nothing Then  
    Select Case AuthenticationOptionListBox.SelectedItem.Value
      Case "Anonymous"
        Return ProfileAuthenticationOption.Anonymous
      Case "Authenticated"
        return ProfileAuthenticationOption.Authenticated
      Case Else
        Return ProfileAuthenticationOption.All
    End Select
  End If

  Return ProfileAuthenticationOption.All
End Function

Public Sub DeleteAllInactiveButton_OnClick(sender As Object, args As EventArgs)
  deletedProfiles = ProfileManager.DeleteInactiveProfiles(authOption, _
                        DateTime.Now.Subtract(new TimeSpan(inactiveDays, 0, 0 ,0)))
  DeletedMessage.Text = deletedProfiles.ToString() & " profiles deleted."
  GetProfiles()
End SUb

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

<form id="form1" runat="server">
  <h3>Profile List</h3>

  <table border="0" cellpadding="3" cellspacing="3">
    <tr>
      <td valign="top">Authentication Option</td>
      <td valign="top"><asp:ListBox id="AuthenticationOptionListBox" rows="3" runat="Server"
                                    AutoPostBack="True"
                                    OnSelectedIndexChanged="AuthenticationOptionListBox_OnSelectedIndexChanged">
                         <asp:ListItem value="All" selected="True">All</asp:ListItem>
                         <asp:ListItem value="Authenticated">Authenticated</asp:ListItem>
                         <asp:ListItem value="Anonymous">Anonymous</asp:ListItem>
                       </asp:ListBox>
      </td>
    </tr>
    <tr>
      <td valign="top" style="width:160">
        Number of Days for Profile to be considered "inactive"</td>
      <td valign="top" style="width:200">
        <asp:TextBox id="InactiveDaysTextBox" runat="Server" MaxLength="3" Columns="3" />
        <asp:Button id="ModifyInactiveDaysButton" runat="server" Text="Refresh Results" 
           OnClick="ModifyInactiveDaysButton_OnClick" /><br />
        <asp:Button id="DeleteAllInactiveButton" runat="Server"
           Text="Delete All Inactive Profiles" OnClick="DeleteAllInactiveButton_OnClick" />
      </td>
      <td valign="top">
        <asp:RequiredFieldValidator id="InactiveDaysRequiredValidator" runat="server"
           ControlToValidate="InactiveDaysTextBox" ForeColor="red"
           Display="Static" ErrorMessage="Required" />
        <asp:RegularExpressionValidator id="InactiveDaysValidator" runat="server"
           ControlToValidate="InactiveDaysTextBox" ForeColor="red"
           Display="Static" ValidationExpression="[0-9]*" 
           ErrorMessage="Inactive Days must be a whole number less than 1000 (e.g. 30, 120)" />
     </td>
    </tr>
    <tr>
      <td><asp:Label id="DeletedMessage" runat="server" /></td>
      <td><asp:Label id="TotalProfilesLabel" runat="server" /> inactive profiles found.</td>
    </tr>
  </table>

    <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:GridView id="ProfileGrid" runat="server" AutoGenerateColumns="False"
                OnRowCommand="ProfileGrid_Delete"
                CellPadding="2" CellSpacing="1" Gridlines="None">
    <HeaderStyle BackColor="darkblue" ForeColor="white" />
    <Columns>
      <asp:BoundField HeaderText="User Name" DataField="Username" />
      <asp:BoundField HeaderText="Is Anonymous" DataField="IsAnonymous" />
      <asp:BoundField HeaderText="Last Updated" DataField="LastUpdatedDate" />
      <asp:BoundField HeaderText="Last Activity" DataField="LastActivityDate" />
      <asp:ButtonField HeaderText="Action" Text="Delete" ButtonType="Link" />
    </Columns>
  </asp:GridView>

</form>

</body>
</html>

설명

ASP.NET 프로필 저장 및 검색 데이터베이스와 같은 데이터 원본에서 사용자 설정이 됩니다. 사용 하 여 사용자 프로필에 액세스 합니다 Profile 속성이 현재 HttpContext합니다. 프로필 정보 및 속성 값은 프로필 공급자를 사용 하 여 관리 됩니다.

ProfileManager 클래스는 프로필 설정을 관리하고, 사용자 프로필을 검색하고, 더 이상 사용되지 않는 사용자 프로필을 삭제하는 데 사용됩니다. ProfileManager 클래스는 정적 메서드 및 속성을 참조 하 여 액세스할 수 있는 제공 된 ProfileManager 애플리케이션 코드에서 클래스. 예제를 보려면 이 항목의 예제 섹션과 클래스 멤버에 대한 항목의 추가 예제를 ProfileManager 참조하세요.

기본적으로 사용자 프로필은 모든 ASP.NET 애플리케이션에 대 한 비활성화 됩니다. 사용자 프로필을 사용하도록 설정하려면 다음 예제와 같이 프로필 구성 요소의 특성을 true로 설정합니다enabled.

<configuration>
  <system.web>
    <profile enabled="true" />
  </system.web>
</configuration>

사용자 프로필에 대한 자세한 내용은 ASP.NET 프로필 속성 개요를 참조하세요.

프로필 공급자는 사용자 프로필에 속성을 저장하고 검색하는 데 사용됩니다. .NET Framework SQL Server 데이터베이스에 사용자 프로필 속성을 저장하는 클래스를 포함합니다SqlProfileProvider. SqlProfileProvider 명명 AspNetSqlProvider 된 인스턴스는 컴퓨터 구성에서 기본 프로필 공급자로 지정됩니다. 인스턴스는 AspNetSqlProvider 로컬 웹 서버의 SQL Server 데이터베이스에 연결합니다. 다음 예제와 같이 공급자 구성 요소 및 defaultProvider 프로필 구성 요소의 특성을 사용하여 다른 SQL Server 연결하는 속성을 기본 프로필 공급자로 지정할 SqlProfileProvider 수 있습니다.

<configuration>
  <connectionStrings>
    <add name="SqlServices" connectionString=
      "Data Source=MySqlServer;Integrated Security=SSPI;Initial Catalog=aspnetdb;" />
  </connectionStrings>
  <system.web>
    <profile defaultProvider="SqlProvider">
      <providers>
        <clear />
        <add name="SqlProvider"
          type="System.Web.Profile.SqlProfileProvider"
          connectionStringName="SqlServices"
          applicationName="MyApplication" />
      </providers>
    </profile>
  </system.web>
</configuration>

속성

ApplicationName

프로필 정보를 저장하고 검색할 애플리케이션의 이름을 가져오거나 설정합니다.

AutomaticSaveEnabled

사용자 프로필이 ASP.NET 페이지의 실행이 끝날 때 자동으로 저장되는지 여부를 나타내는 값을 가져옵니다.

Enabled

사용자 프로필이 애플리케이션에 사용되는지 여부를 나타내는 값을 가져옵니다.

Provider

애플리케이션의 기본 프로필 공급자에 대한 참조를 가져옵니다.

Providers

ASP.NET 애플리케이션의 프로필 공급자 컬렉션을 가져옵니다.

메서드

AddDynamicProfileProperty(ProfilePropertySettings)

프로필 속성을 프로그래밍 방식으로 추가합니다.

DeleteInactiveProfiles(ProfileAuthenticationOption, DateTime)

마지막 작업 날짜와 시간이 지정된 날짜와 시간 이전인 사용자 프로필 데이터를 삭제합니다.

DeleteProfile(String)

지정된 사용자 이름의 프로필을 데이터 소스에서 삭제합니다.

DeleteProfiles(ProfileInfoCollection)

제공된 프로필 목록의 프로필 속성과 정보를 데이터 소스에서 삭제합니다.

DeleteProfiles(String[])

제공된 사용자 이름 목록의 프로필 속성과 정보를 삭제합니다.

FindInactiveProfilesByUserName(ProfileAuthenticationOption, String, DateTime)

마지막 작업 날짜가 지정된 날짜와 시간이거나 그 이전이고 프로필의 사용자 이름이 지정된 이름과 일치하는 모든 프로필의 프로필 정보를 검색합니다.

FindInactiveProfilesByUserName(ProfileAuthenticationOption, String, DateTime, Int32, Int32, Int32)

마지막 작업 날짜가 지정된 날짜와 시간이거나 그 이전이고 프로필의 사용자 이름이 지정된 이름과 일치하는 프로필의 프로필 정보를 데이터 페이지에서 검색합니다.

FindProfilesByUserName(ProfileAuthenticationOption, String)

사용자 이름이 지정된 이름과 일치하는 프로필에 대한 모든 프로필 정보를 검색합니다.

FindProfilesByUserName(ProfileAuthenticationOption, String, Int32, Int32, Int32)

사용자 이름이 지정된 이름과 일치하는 프로필에 대한 프로필 정보를 데이터 페이지에서 검색합니다.

GetAllInactiveProfiles(ProfileAuthenticationOption, DateTime)

마지막 작업 날짜가 지정된 날짜와 시간 이전인 프로필의 모든 사용자 프로필 데이터를 검색합니다.

GetAllInactiveProfiles(ProfileAuthenticationOption, DateTime, Int32, Int32, Int32)

마지막 작업 날짜가 지정된 날짜와 시간이거나 그 이전인 사용자 프로필에 대한 ProfileInfo 개체의 페이지를 검색합니다.

GetAllProfiles(ProfileAuthenticationOption)

데이터 소스에서 프로필에 대한 사용자 프로필 데이터를 검색합니다.

GetAllProfiles(ProfileAuthenticationOption, Int32, Int32, Int32)

사용자 프로필 데이터의 페이지를 검색합니다.

GetNumberOfInactiveProfiles(ProfileAuthenticationOption, DateTime)

마지막 작업 날짜가 지정된 날짜이거나 그 이전인 프로필의 수를 가져옵니다.

GetNumberOfProfiles(ProfileAuthenticationOption)

데이터 소스의 프로필 수를 가져옵니다.

적용 대상

추가 정보