Share via


ChangePassword.ChangingPassword 이벤트

정의

멤버 자격 공급자가 사용자 계정의 암호를 변경하기 전에 발생합니다.

public:
 event System::Web::UI::WebControls::LoginCancelEventHandler ^ ChangingPassword;
public event System.Web.UI.WebControls.LoginCancelEventHandler ChangingPassword;
member this.ChangingPassword : System.Web.UI.WebControls.LoginCancelEventHandler 
Public Custom Event ChangingPassword As LoginCancelEventHandler 

이벤트 유형

예제

다음 코드 예제를 사용 하는 ASP.NET 페이지를 사용 하는 방법을 보여 줍니다는 ChangePassword 컨트롤 및에 대 한 처리기를 포함 합니다 ChangingPassword 라는 이벤트 ChangingPassword합니다. 이벤트 처리기의 코드에 저장 된 이전 암호를 비교 합니다 CurrentPassword 속성에 저장 된 새 암호로 NewPassword합니다. 두 암호가 동일한 경우 실패 암호를 변경 합니다.

합니다 ChangePassword 집합을 제어 합니다 DisplayUserName 속성을 true 사용자가 자신의 사용자 이름을 입력할 수 있도록 합니다. 즉, 사용자 페이지 보기에 로그온 할 필요가 없습니다.

코드 예제에서는 ASP.NET 멤버 자격 및 폼 인증 및 사용자가 만들어졌는지 해당 이름 및 암호를 알고 사용 하 여 ASP.NET 웹 사이트를 구성한 경우를 가정 합니다. 자세한 내용은 방법: 간단한 폼 인증 구현합니다.

<%@ Page Language="C#" AutoEventWireup="True" %>

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

  void Page_Load(Object sender, EventArgs e)
  {
    //Manually register the event-handling methods.
    ChangePassword1.ChangingPassword += new LoginCancelEventHandler(this._ChangingPassword);
  }

  void _ChangingPassword(Object sender, LoginCancelEventArgs e)
  {
    if (ChangePassword1.CurrentPassword.ToString() == ChangePassword1.NewPassword.ToString())
    {
      Message1.Visible = true;
      Message1.Text = "Old password and new password must be different.  Please try again.";
      e.Cancel = true;
    }
    else
    {
      //This line prevents the error showing up after a first failed attempt.
      Message1.Visible = false;
    }
  }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
  <title>ChangePassword including a ChangingPassword event handler</title>
</head>
<body>
  <form id="form1" runat="server">
  <div style="text-align:center">

    <h1>ChangePassword</h1>
    
    <asp:LoginView ID="LoginView1" Runat="server" 
      Visible="true">
      <LoggedInTemplate>
        <asp:LoginName ID="LoginName1" Runat="server" FormatString="You are logged in as {0}." />
        <br />
      </LoggedInTemplate>
      <AnonymousTemplate>
        You are not logged in
      </AnonymousTemplate>
    </asp:LoginView><br />
    
    <asp:ChangePassword ID="ChangePassword1" Runat="server"
      BorderStyle="Solid" 
      BorderWidth="1" 
      CancelDestinationPageUrl="~/Default.aspx" 
      DisplayUserName="true" 
      OnChangingPassword="_ChangingPassword"
      ContinueDestinationPageUrl="~/Default.aspx" >
    </asp:ChangePassword><br />
  
    <asp:Label ID="Message1" Runat="server" ForeColor="Red" /><br />

    <asp:HyperLink ID="HyperLink1" Runat="server" 
      NavigateUrl="~/Default.aspx">
      Home
    </asp:HyperLink>
    
  </div>
  </form>
</body>
</html>
<%@ Page Language="VB" AutoEventWireup="True" %>

<!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 PageLoad(ByVal Sender As Object, ByVal e As EventArgs)
    'Manually register the event-handling methods.
    AddHandler ChangePassword1.ChangingPassword, AddressOf Me._ChangingPassword
  End Sub

  Public Sub _ChangingPassword(ByVal Sender As Object, ByVal e As LoginCancelEventArgs)
    If (ChangePassword1.CurrentPassword.ToString() = ChangePassword1.NewPassword.ToString) Then
      Message1.Visible = True
      Message1.Text = "Old password and new password must be different.  Please try again."
      e.Cancel = True
    Else
      'This line prevents the error showing up after a first failed attempt.
      Message1.Visible = False
    End If
  End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
  <title>ChangePassword including a ChangingPassword event handler</title>
</head>
<body>
  <form id="form1" runat="server">
  <div style="text-align:center">

    <h1>ChangePassword</h1>
    
    <asp:LoginView ID="LoginView1" Runat="server" 
      Visible="true">
      <LoggedInTemplate>
        <asp:LoginName ID="LoginName1" Runat="server" FormatString="You are logged in as {0}." />
        <br />
      </LoggedInTemplate>
      <AnonymousTemplate>
        You are not logged in
      </AnonymousTemplate>
    </asp:LoginView><br />
    
    <asp:ChangePassword ID="ChangePassword1" Runat="server"
      BorderStyle="Solid" 
      BorderWidth="1" 
      CancelDestinationPageUrl="~/Default.aspx" 
      DisplayUserName="true" 
      OnChangingPassword="_ChangingPassword"
      ContinueDestinationPageUrl="~/Default.aspx" >
    </asp:ChangePassword><br />
  
    <asp:Label ID="Message1" Runat="server" ForeColor="Red" /><br />

    <asp:HyperLink ID="HyperLink1" Runat="server" 
      NavigateUrl="~/Default.aspx">
      Home
    </asp:HyperLink>
    
  </div>
  </form>
</body>
</html>

설명

합니다 ChangingPassword 에 지정 된 멤버 자격 공급자 전에 이벤트가 발생 합니다 MembershipProvider 사용자 계정의 암호를 변경 하려면 속성 이라고 합니다.

사용 하 여는 ChangingPassword 확인 하기 위해 새 암호를 확인 하는 같은 암호를 변경 하기 전에 필요한 처리를 수행 하는 이벤트의 일반적인 암호 목록을 아닙니다. 후 사용자에 대 한 새 권한 부여 토큰에 설정 합니다 ChangingPassword 이벤트 전에 ChangedPassword 이벤트.

ChangingPassword 설정 하 여 이벤트를 취소할 수 있습니다는 Cancel 의 속성을 LoginCancelEventArgs 개체를 true 멤버 자격 공급자를 호출할 수는 이벤트 처리기를 결정 하는 경우.

이벤트 처리에 대한 자세한 내용은 이벤트 처리 및 발생 을 참조하십시오.

적용 대상

추가 정보