Results 1 to 5 of 5

Thread: FromsAuthentication.RedirectFromLoginPage - problem [*Resolved*]

Threaded View

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2001
    Posts
    1,331

    FromsAuthentication.RedirectFromLoginPage - problem [*Resolved*]

    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.

    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>
    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:
                             //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;
    				}
    			}
    Thanks in advance,

    Steve
    Last edited by steve_rm; Apr 19th, 2005 at 05:36 PM. Reason: Resolved
    steve

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width