62,041
社区成员
发帖
与我相关
我的任务
分享
select userId,userName,userTel from T_UserInfo where userId=@userId
private void GetLoginUserInfo(string loginUserId)
{
try
{
Using(SqlConnection conn=new SqlConnection("server=your server ip;database=your db;user=your sql server login user name;pwd=your pwd;"))
{
string strSQL="select userId,userName,userTel from T_UserInfo where userId='"+loginUserId+"'";
SqlCommand cmd=new SqlCommand(strSQL,conn);
conn.Open();
SqlDataReader dr =cmd.ExecuteReader();
int i=0;
while(dr.Read())
{
if(i>0) throw new Exception("more than one user");
Session["UserId"]=dr[0].ToString();
Session["UserName"]=dr[1].ToString();
Session["UserTel"]=dr[2].ToString();
i++;
}
dr.Close();
}
}
catch(Exception ex){ throw ex;}
}
protected void btnLogin_Click(object sender, EventArgs e)
{
GetLoginUserInfo();
//将用户信息显示在页面上
if(Session["UserName"]!=null) this.lblUserName.Text=Session["UserName"].ToString();
if(Session["UserTel"]!=null) thie.lblTelNo.Text=Session["UserTel"].ToString();
//TODO:add your other operations
}
if(Session["UserName"]!=null)
{
//TODO:your code
}
if(Session["UserTel"]!=null)
{
//TODO:your code
}
<%
Sub login()
Ft_UserName=request.Form("Ft_UserName")
Ft_PassWord=request.Form("Ft_PassWord")
'Ft_Code=request.Form("Ft_Code")
if Ft_UserName<>"" then
Call db_conn()
Call dbRs(0,"select * from Ft_User where Ft_UserName='"&Ft_UserName&"' and Ft_PassWord='" & MD5(Ft_PassWord) & "'" )
if rs.eof then
Call Salert("用户名密码错误!","../index.asp")
else
'if Ft_Code<>Session("pSN") then
' Call Salert("请输入正确的验证码!","login.asp")
'else
session("Ft_UserName")=Ft_UserName '登录成功之后写session
response.Redirect "index.asp"
response.end
'end if
end if
end if
End Sub
%>
<%
if session("Ft_UserName")="" then
response.Write "<script>alert('请登录');window.location.href='../index.asp';</script>"
end if
%>
Sub login()
Ft_UserName=request.Form("Ft_UserName")
Ft_PassWord=request.Form("Ft_PassWord")
'Ft_Code=request.Form("Ft_Code")
if Ft_UserName<>"" then
Call db_conn()
Call dbRs(0,"select * from Ft_User where Ft_UserName='"&Ft_UserName&"' and Ft_PassWord='" & MD5(Ft_PassWord) & "'" )
if rs.eof then
Call Salert("用户名密码错误!","../index.asp")
else
'if Ft_Code<>Session("pSN") then
' Call Salert("请输入正确的验证码!","login.asp")
'else
session("Ft_UserName")=Ft_UserName
response.Redirect "index.asp"
response.end
'end if
end if
end if
End Sub
using System.Web.Security;
using System.Runtime.InteropServices;
[DllImport("advapi32.dll", CharSet=CharSet.Auto)]
public static extern int LogonUser(String lpszUserName,
String lpszDomain,
String lpszPassword,
int dwLogonType,
int dwLogonProvider,
ref IntPtr phToken);
public const int LOGON32_LOGON_INTERACTIVE = 2;
public const int LOGON32_PROVIDER_DEFAULT = 0;
void Login_Click(Object sender, EventArgs E)
{
IntPtr token = IntPtr.Zero;
if(LogonUser(UserName.Value,
UserDomain.Value,
UserPass.Value,
LOGON32_LOGON_INTERACTIVE,
LOGON32_PROVIDER_DEFAULT,
ref token) != 0)
{
FormsAuthentication.RedirectFromLoginPage(UserName.Value,
PersistCookie.Checked);
}
else
{
lblResults.Text = "Invalid Credentials: Please try again";
}
}
using System.DirectoryServices;
DirectorySearcher ds = new DirectorySearcher("(sAMAccountName=" + Request.LogonUserIdentity.Name.Split('\\')[1] + ")");
SearchResult sr = ds.FindOne();
Response.Write("姓名:" + sr.Properties["name"][0].ToString());
Response.Write("<br>电话:" + sr.Properties["telephonenumber"][0].ToString());