사용자가 내 웹 사이트에 로그인 할 수있는 인증 쿠키를 만들려고합니다.FormsAuthentication.Authenticate를 사용하여 로그인하십시오.
나는 로그인과 같은 형태가 있습니다
<asp:TextBox ID="txtUsername" runat="server" MaxLength="10" Text="Sam001" ></asp:TextBox>
<asp:TextBox ID="txtPassword" runat="server" MaxLength="10" Text="Pass01" ></asp:TextBox>
<asp:Label ID="status" runat="server" ></asp:Label>
<asp:Button CssClass="button" ID="Submit" runat="server" Text="Logga in" OnClick="Login_Click" />
와 그 버튼 뒤에 코드에서이 작업을 수행합니다
protected void Login_Click(object sender, EventArgs e)
{
DbReader listData = new DbReader();
Employee tempEmp = null;
if ((tempEmp = listData.GetUser(txtUsername.Text, txtPassword.Text)) != null) // check if username and pw was correct
{
FormsAuthentication.SetAuthCookie(tempEmp.EID, false); // create auth cookie
Debug.WriteLine("auth cookie set for: " + tempEmp.EID);
if (FormsAuthentication.Authenticate(tempEmp.EID, txtPassword.Text)) // check if name and pass is valid
{
Debug.WriteLine("auth validation ok");
FormsAuthentication.RedirectFromLoginPage(tempEmp.EID, false); // redirect
status.Text = User.Identity.Name; // set status to the Name property of the auth cookie
}
else
{
status.Text = "failed to Authenticate";
}
}
else
{
status.Text = "failed to get user";
}
}
와의 Web.config에는 다음과 같습니다
<authentication mode="Forms">
<forms name="LoggedInUser" loginUrl="~/Login.aspx" protection="All" timeout="10" path="/" />
</authentication>
어떻게 항상 "인증 실패"가 발생합니까? 사용자가 로그인하여 특정 페이지에 액세스해야하는 인증 쿠키를 만들고 싶을 때 나는 무엇을 잘못하고 있습니까?
어떻게 든 데이터베이스에 대해 유효성을 검사 할 수 있습니까? Membership.ValidateUser()를 사용하면이 오류를 알려주는 버그가 있습니다. 파일 또는 어셈블리 'MySql.Web, Version = 6.7.4.0, Culture = neutral, PublicKeyToken = c5687fc88969c44d'또는 해당 종속성 중 하나를로드 할 수 없습니다. 시스템이 지정된 파일을 찾을 수 없습니다. – jt123
@ user2059696 : 데이터베이스에 대해 절대적으로 유효성을 검사 할 수 있습니다. 우리가하는 일은 사용자 이름과 암호를 확인하는 코드를 작성하는 것입니다. 사용자가 올바른 자격 증명을 입력했는지 확인한 후에는 SethAuthCookie를 사용하여 사용자의 유효성을 검증합니다. 자신의 인증 시스템을 보유하고 있지 않거나 유지하고 싶지 않다면 Microsoft가 제공하는 인증 시스템 중 하나를 사용할 수 있습니다 (몇 가지가 있습니다). 필자가 만든 다른 응용 프로그램의 경우 SQL 멤버십 API의 소스 코드를 통합하여 원하는 방식으로 처리했습니다. –