LINQ登录方式
本文关键字:方式 登录 LINQ | 更新日期: 2023-09-27 18:16:24
我尝试使用LINQ登录到我的网站。当我尝试登录时,他只是重新加载,没有任何响应。
我的代码:
public partial class Log_in : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
private void ActiveLink()
{
if (HttpContext.Current.CurrentHandler.ToString().ToLower().Contains("username"))
{
username.Attributes.Add("class", "active");
}
}
protected void submit_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("ConnectionString");
con.Open();
String usernames = username.Text;
String passwords = password.Text;
DataClasses1DataContext daneden = new DataClasses1DataContext();
var user = (from s in daneden.logins
where s.username == usernames && s.passwords == passwords
select s);
if (user != null)
{
Response.Redirect("About.aspx");
}
else
{
usernameerror.Text = "Error!";
}
con.Close();
}
}
var user = (from s in daneden.logins
where s.username == usernames && s.passwords == passwords
select s).FirstOrDefault();
交替:
var user = daneden.logins
.FirstOrDefault(s=> s.username == usernames && s.passwords == passwords);