May 28, 2019 09:04 AM|Brando ZWZ|LINK
authentication when logging in to asp.net, the command x must be used with the Web.config file, I have not found the command x running with sql server or the command x running with microsoft access. I want to find an example of the command x running with sql
server or the command x running with microsoft acess, maybe the command x is difficult to apply to sql server or microsoft access ?
According to the
MSFT article, you could find the FormsAuthentication.Authenticate is used to validate a user name and password against credentials stored in the
It doesn't supprot directly validate the user from database.
Normally, if we want to use FormsAuthentication to authenticate the user according to database record, I suggest you could write custom validate method. Like below:
bool ValidateUser(string user, string pass)
string connStr = ConfigurationManager.ConnectionStrings["Main"].ConnectionString;
using (SqlConnection conn = new SqlConnection(connStr))
string sql = "select email from users where email = @email and password = @password";
SqlCommand cmd = new SqlCommand(sql, conn);
return cmd.ExecuteScalar() is string;
If validated the user is successed, then you could use FormsAuthentication.RedirectFromLoginPage(txtUserName.Text, true);
to let the user pass the form authentication.
More details, you could refer to this article: