.NET에서 로그인하는 방법
로그인.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace login
{
public partial class login : System.Web.UI.Page
{
public object LoginStatus1 { get; private set; }
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
int ViewstateVal = 1;
if (ViewState["count"] != null)
{
ViewstateVal = Convert.ToInt32(ViewState["count"]) + 1;
ViewState["count"] = ViewstateVal.ToString();
}
else { ViewState["count"] = "1"; }
TextBox1.Text = ViewstateVal.ToString();
ViewState["count"] = ViewstateVal.ToString();
}
}
protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
{
bool verify = false;
verify = MyAuthenticationLogic(Login1.UserName, Login1.Password);
e.Authenticated = verify;
if (e.Authenticated == true)
{
HttpCookie c1 = new HttpCookie("loginInfo");
c1["Name"] = Login1.UserName;
c1["Password"] = Login1.Password;
Response.Cookies.Add(c1);
Server.Transfer("redirect.aspx?username=" + Login1.UserName + "&password=" + Login1.Password, true);
}
else{
errMsg.LoginText = "Enter the correct Credentials";
}
}
protected bool MyAuthenticationLogic(string username, string password)
{
if (username == "Hrushikesh" && password == "CodeMaster")
{
return true;
}
else
{
return false;
}
}
protected void btn1_Click(object sender, EventArgs e)
{
Server.Transfer("redirect.aspx?username=" + Login1.UserName + "&password=" + Login1.Password, false);
}
}
}
Register.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace login
{
public partial class redirect : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string username = Request.QueryString["Username"];
string password = Request.QueryString["password"];
msgTxt.Text = "Welcome " + username + " Your Password is : " + password;
HttpCookie c1 = Request.Cookies["loginInfo"];
lbl1.Text ="Passord Is : "+ c1["Password"];
}
}
}
스크린샷
Read More
Reference
이 문제에 관하여(.NET에서 로그인하는 방법), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/harsh123/how-to-make-login-in-net-3mkg텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)