8 Replies - 1161 Views - Last Post: 08 August 2012 - 05:41 PM Rate Topic: -----

#1 tricket_7  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 104
  • Joined: 09-May 09

C#.net webform in existing website

Posted 07 August 2012 - 08:04 AM

I have a really stupid question, I want to create a login form on an existing website page, if I am creating the form in visual studio 2010 do I create a web application/ new webform? Or do I create new website/ new webform? I understand the coding, I just dont really know where to start.
Is This A Good Question/Topic? 0
  • +

Replies To: C#.net webform in existing website

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9573
  • View blog
  • Posts: 36,253
  • Joined: 12-June 08

Re: C#.net webform in existing website

Posted 07 August 2012 - 08:05 AM

If the existing page isn't in a solution then yes.. you can just create a new project with a default page on it and go nuts.
Was This Post Helpful? 0
  • +
  • -

#3 tricket_7  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 104
  • Joined: 09-May 09

Re: C#.net webform in existing website

Posted 07 August 2012 - 09:25 AM

I am unsure of how to go about the btnLogin_Click event to validate the username and password that are typed into the login form. This will check against a microsoft access database can you help get me started. First I have the login form, second I have the codebehind
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="FreightBillInquiry.aspx.cs" Inherits="FBInquiry.FreightBillInquiry" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
   
</head>
<body>
    <form id="form1" runat="server">
    <div>
    New users can <a href="CarrierRegistration.aspx">register</a> here.<br />
   
    <table  border="0" style="border-width: 3px; border-color:#c2c2c2;
border-style: solid;">  
   <tr>
   <td></td>
   <td><strong>Please Login</strong></td></tr>
    <tr>
    <td>
        <asp:Label ID="lblUser" runat="server" Text="Username:"></asp:Label>
    </td>
    <td>
        <asp:TextBox ID="txtUser" runat="server"></asp:TextBox>
    </td></tr>
    <tr>
    <td>
        <asp:Label ID="lblPass" runat="server" Text="Password:"></asp:Label>
    </td>
    <td>
        <asp:TextBox ID="txtPass" runat="server"></asp:TextBox>
    </td></tr>
    <tr>
    <td></td>
    <td>
       
    </td></tr>
    <tr>
    <td></td>
    <td> <asp:Button ID="btnLogin" runat="server" Text="Login" 
            onclick="btnLogin_Click" /></td></tr></table>
    
    </div>
    </form>
</body>
</html>



code behind
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace FBInquiry
{
    public partial class FreightBillInquiry : System.Web.UI.Page
    {

        System.Data.OleDb.OleDbConnection con;
        DataSet dsl;
        System.Data.OleDb.OleDbDataAdapter da;

        protected void Form1_Load(object sender, EventArgs e)
        {
            con = new System.Data.OleDb.OleDbConnection();
            dsl = new DataSet();
            con.ConnectionString = "PROVIDER=Microsoft.Jet.OleDb.4.0; Data Source=C:\\Users\\Christie\\Desktop\\login\\FBInquiry\\App_Data\\prosearchusers.mdb";
            con.Open();

            string sql = "SELECT * FROM tblCustRecords";
            da=new System.Data.OleDb.OleDbDataAdapter(sql,con);

            con.Close();
            con.Dispose();

        }

        protected void btnLogin_Click(object sender, EventArgs e)
        {

        }
    }
}


Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9573
  • View blog
  • Posts: 36,253
  • Joined: 12-June 08

Re: C#.net webform in existing website

Posted 07 August 2012 - 09:42 AM

The gist is simple.. on your button click for 'log in'... you:

check to make sure there's values (trim the spaces) in the name and password field
from there make a connection to your database..
the sql statement would be something like
SELECT 1 
FROM <TABLE NAME> 
WHERE <user name column> = <user name data from the textbox> AND <password column> = <password data from the textbox>

Throw the open connection and sql string into a sqlcommand object.
If 1 is returned then it matches and the user can continue.. if not then throw a warning.
This means you need to catch the output.. I suggest something simple like using the sqlcommand's "execute scalar" and the return that way.

Of course this is just the nitty gritty.. I would suggest using parametrized queries (don't try and butcher a sql string statement)... that the password be encrypted on the way in and just compare encrypted values.. and this doesn't do much for the second half of a login page - making sure that the user is identified as 'logged in' during the session.
Was This Post Helpful? 0
  • +
  • -

#5 tricket_7  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 104
  • Joined: 09-May 09

Re: C#.net webform in existing website

Posted 08 August 2012 - 01:40 PM

This is what I have so far, but I dont understand about the sqlCommand object

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.OleDb;




namespace FBInquiry
{

    public class DataLayer
    {
        private OleDbConnection conn;
        private readonly String connString;

        public DataLayer()
        {
            connString = @"PROVIDER=Microsoft.Jet.OleDb.4.0; Data Source=C:\Users\Christie\Desktop\login\FBInquiry\App_Data\prosearchusers.mdb";
            conn = new OleDbConnection(connString);                    
        }

        private void OpenConnection()
        {
            if (conn.State != ConnectionState.Open)
                conn.Open();
        }

        public DataTable FillTable(String sql)
        {
            DataTable table = new DataTable();
            using (OleDbDataAdapter da = new OleDbDataAdapter(sql, conn))
            {
                
                da.Fill(table);
            }
            return table;
        }

        public Boolean Login(String user, String pass)
        {
            SqlCommand cmd = new SqlCommand("SELECT pass FROM users WHERE user = '" + user + "' ", Connection);
            sqlDataReader reader = cmd.ExecuteReader();
            while (reader.Read())
            {
                String s = (String)reader[0];
            }
            return false;
        }

        protected void btnLogin_Click(object sender, EventArgs e)
        {
             
        }
    }
}


sqlCommand and sqlDataReader
Was This Post Helpful? 0
  • +
  • -

#6 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9573
  • View blog
  • Posts: 36,253
  • Joined: 12-June 08

Re: C#.net webform in existing website

Posted 08 August 2012 - 01:51 PM

What don't you understand?
Was This Post Helpful? 0
  • +
  • -

#7 tricket_7  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 104
  • Joined: 09-May 09

Re: C#.net webform in existing website

Posted 08 August 2012 - 02:20 PM

View Postmodi123_1, on 08 August 2012 - 02:51 PM, said:

What don't you understand?

I dont understand how to set up the sqlCommand Object,the DataReader object, or where to input my sql query to check for username and password

Am I on the right track with the code I posted?
Was This Post Helpful? 0
  • +
  • -

#8 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9573
  • View blog
  • Posts: 36,253
  • Joined: 12-June 08

Re: C#.net webform in existing website

Posted 08 August 2012 - 02:42 PM

There are plenty of tutorials on that.. here or on MSDN.


http://www.dreaminco...basics-in-c%23/
http://www.dreaminco...a-mysql-server/
http://www.dreaminco...iew-using-c%23/
http://www.dreaminco...asics-in-vbnet/
http://www.dreaminco...imple-database/
Was This Post Helpful? 0
  • +
  • -

#9 tricket_7  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 104
  • Joined: 09-May 09

Re: C#.net webform in existing website

Posted 08 August 2012 - 05:41 PM

View Postmodi123_1, on 08 August 2012 - 03:42 PM, said:


Thank you so much, I will definitely check these out
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1