Xin chào skp,
Bạn có thể sử dụng Trạng thái phiên để lưu tên người dùng và id rồi truy xuất sau khi đăng nhập
Kiểm tra ví dụ này. Bây giờ hãy tham khảo và sửa mã của bạn
Tham khảo bài viết dưới đây tôi đã tạo ra một ví dụ
Kiểm tra ví dụ này. Bây giờ hãy tham khảo và sửa mã của bạn
HTML
Đăng nhập. aspx
Document
{{message}}
Sự thành công. aspx
C#
User Name :
<%=this.UserName%>
User Id :
<%=this.UserId%>
VB. Net
User Name :
<%=Me.UserName%>
User Id :
<%=Me.UserId%>
Mã số
Trang đăng nhập
C#
[System.Web.Services.WebMethod] public static string ValidateUser(string username, string password) { string status = ""; int userId = 0; string constr = System.Configuration.ConfigurationManager.ConnectionStrings["constr"].ConnectionString; using (System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection(constr)) { using (System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand("Validate_User")) { cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@Username", username); cmd.Parameters.AddWithValue("@Password", password); cmd.Connection = con; con.Open(); userId = Convert.ToInt32(cmd.ExecuteScalar()); System.Web.HttpContext.Current.Session["UserName"] = username; System.Web.HttpContext.Current.Session["UserId"] = userId; con.Close(); } switch (userId) { case -1: status = "Username and/or password is incorrect."; break; case -2: status = "Account has not been activated."; break; default: status = userId.ToString(); break; } } return status; }VB. Net
Public Shared Function ValidateUser(ByVal username As String, ByVal password As String) As String Dim status As String = "" Dim userId As Integer = 0 Dim constr As String = System.Configuration.ConfigurationManager.ConnectionStrings("constr").ConnectionString Using con As System.Data.SqlClient.SqlConnection = New System.Data.SqlClient.SqlConnection(constr) Using cmd As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand("Validate_User") cmd.CommandType = System.Data.CommandType.StoredProcedure cmd.Parameters.AddWithValue("@Username", username) cmd.Parameters.AddWithValue("@Password", password) cmd.Connection = con con.Open() userId = Convert.ToInt32(cmd.ExecuteScalar()) System.Web.HttpContext.Current.Session("UserName") = username System.Web.HttpContext.Current.Session("UserId") = userId con.Close() End Using Select Case userId Case -1 status = "Username and/or password is incorrect." Case -2 status = "Account has not been activated." Case Else status = userId.ToString() End Select End Using Return status End FunctionTrang thành công
C#
public string UserName { get; set; } public string UserId { get; set; } protected void Page_Load(object sender, EventArgs e) { if (Session["UserName"] != null && Session["UserId"] != null) { UserName = Session["UserName"].ToString(); UserId = Session["UserId"].ToString(); } }VB. Net
Public Property UserName As String Public Property UserId As String Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load If Session("UserName") IsNot Nothing AndAlso Session("UserId") IsNot Nothing Then UserName = Session("UserName").ToString() UserId = Session("UserId").ToString() End If End SubẢnh chụp màn hình
Làm cách nào để lấy chi tiết người dùng đã đăng nhập Windows bằng JavaScript?
Nếu tập lệnh đang chạy trên Microsoft Windows trong HTA hoặc tương tự, bạn có thể thực hiện việc này. var wshshell=new ActiveXObject("wscript. shell"); var username=wshshell. ExpandEnvironmentStrings("%username%");
Làm cách nào để đăng nhập tên người dùng trong JavaScript?
Dưới đây là một số ví dụ. .
To Get User Display Name: var currentUserName=_spPageContextInfo.userDisplayName; .. .
To Get User Login Name: var currentUserLoginName=_spPageContextInfo.userLoginName; .. .
Để lấy Id người dùng. .
Để có được tiêu đề web
Tôi có thể tìm thông tin đăng nhập Windows của mình ở đâu?
Đối với người dùng Windows, .
Nhấn Control + Alt + Delete
Nhấp vào Trình quản lý tác vụ
Nhấp vào Người dùng. Tên người dùng của bạn sẽ được liệt kê trong 'Người dùng'
Làm cách nào để có được người dùng Windows trong Angular?
Nhận người dùng hiện tại (Góc) .
Tạo ứng dụng mới với. .
Để lấy tên của người dùng được xác thực, bạn có thể làm như sau. .
Để chỉ ủy quyền cho một số vai trò nhất định có quyền truy cập vào bộ điều khiển, bạn có thể sử dụng lại thuộc tính Ủy quyền. .
Chạy ứng dụng, đăng nhập và kiểm tra người dùng hiện tại