Hello
I am using forms authentication which worked fine using this code below. In the project l have customerlist set as the startup page, and a login page. If there are no cookies on the users computer it will rediret to the customerlist page, else the login page will display and ask the user to login. All this works fine.
I have now changed this to use a database, so i am not using the code in the web.config file. This is because there will be a lot of people accessing. So l am using a sql query to see if the username and password is in the database. My problem is how can l check for cookies and then redirect to the customerlist page. When l am not using the web.config file.Code://When the user clicks the login button - execute this code if ( FromsAuthentication.Authenticate( txtUsername.Text, txtPassword.Text) ) { FromsAuthentication.RedirectFromLoginPage(txtUsername.Text, chkRemember.Checked) } In the web.config file l had the usernames and passwords. <authentication mode="Forms"> <forms name="AuthTicket" protection="All" loginUrl="Login.aspx" path="/" timeout="20"> <credentials passwordFormat="Clear"> <user name="John" password="john"/> <user name="Mary" password="mary"/> <user name="Glen" password="glenn"/> </credentials> </forms> </authentication> and.... <location path="CustomerList.aspx"> <system.web> <authorization> <deny users="?"/> </authorization> </system.web> </location>
Thanks in advance,Code://This is the code l am using //Check to see if there are any cookies on the users computer - Don't know how to do this try { SqlConnection cnn = new SqlConnection("server = steves-pc; initial catalog = Condo; integrated security = true"); cnn.Open(); SqlCommand cmd = cnn.CreateCommand(); cmd.CommandType = CommandType.Text; cmd.CommandText = "SELECT * FROM [User] " + "WHERE username = '" + username + "' AND UserPassword = '" + userPassword + "' "; SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.SingleRow); if ( dr.Read() ) { if ( dr["Username"].ToString() == username && dr["UserPassword"].ToString() == userPassword ) { FromsAuthentication.SetAuthCookie(Username, ture) //Redirect to the customerlist page - Don't know how to do this } else { //Deny access } } else { //Deny access; } }
Steve




Reply With Quote