本文介绍了如何使用EF,linq和Web表单创建登录页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

H
我正在制作一个ASP.NET Web Forms应用程序,我正在寻找一种方法来做一个好的,安全的,易于制作的登录页面。

我的主要问题是我已经拥有一个SQL数据库,而且我正在使用EF + LINQ来操作它。因为我不能使用Idenity,Owin和Katana(如果现在有人可以在VS 2012中制作它也会对我有帮助)。

请帮我选择使用EF + LINQ + WEB表格制作登录页面或一些样本的技术。



我是什么尝试过:



投掷:Owin,Idenity和Sql Membership。首先是坏的,因为我需要迁移,第二,因为我需要使用Linq

HI am making an ASP.NET Web Forms app and i'm searching for way to do a good, secured and easy to make Login Page .
My main problem that i already have a SQL DataBase and i'm using EF + LINQ to operate with this . Because of that i can't use Idenity, Owin and Katana ( if some one now how it can be make in VS 2012 it will helps me too ) .
Please help me to choose technology for make Login Page or some samples using EF +LINQ +WEB Forms .

What I have tried:

Make it throw : Owin, Idenity and Sql Membership . First is bad because i need migration for this , second because i need to use Linq

推荐答案

private string GetUserPassword(string loginName) {  
            using (DBEntities db = new DBEntities()) {  
                var user = db.SYSUsers.Where(o => o.LoginName.ToLower().Equals(loginName));  
                if (user.Any())  
                    return user.FirstOrDefault().PasswordEncryptedText;  
                else  
                    return string.Empty;  
            }  
} 

protected void Button1_Click(object sender, EventArgs e){  
		string loginName = txtLoginName.Text.Trim();
        	string password = GetUserPassword(loginName);  
  
                if (string.IsNullOrEmpty(password))  
                    Response.Write("The user login or password provided is incorrect.");  
                else {  
                    if (txtPassword.Text.Equals(password)) {  
                        FormsAuthentication.SetAuthCookie(loginName, false);  
                        Response.Redirect("~/Home.aspx");
   
                        //you can also use the FormsAuthentication.RedirectFromLoginPage() 
                        //to redirect 
                    }  
                    else {  
                        Response.Write("The password provided is incorrect.");  
                    }  
                } 
} 





请注意,上面的代码只是一个简单的代码段,用于描述使用EF和LINQ对WebForms中的用户进行身份验证。您可能需要根据数据库和控件更改部分代码。



Note that the code above is just a simple snippet describing the use of EF and LINQ to authenticate users in WebForms. You may need to change some of the code based on your database and controls.


这篇关于如何使用EF,linq和Web表单创建登录页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 21:29