Simple ASP.Net Login Page using C#

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Feb 2003
Posts: 793
Reputation: Paladine has a spectacular aura about Paladine has a spectacular aura about Paladine has a spectacular aura about 
Solved Threads: 26
Team Colleague
Paladine's Avatar
Paladine Paladine is offline Offline
Master Poster

Re: Simple ASP.Net Login Page using C#

 
0
  #41
Oct 31st, 2006
Microsoft.NET\Framework\v2.0.50727\
This is the reason, you are using this code which is for ASP.NET 1.1 and NOT ASP.NET 2.0. There are some significant differences between 1.1 and 2.0 framework that makes this code non-functional.

So if you want to use 2.0, you will have to debug and modify the code accordingly (I haven't had a free moment to post the 2.0 version of this code yet-- actually 2.0 has many things built in that streamline this). Recommend you check out http://www.asp.net/getstarted/default.aspx?tabid=61

For great video demos on creating a fully usable login and portal site.

Or if you are set on using 1.1, you will have to switch your default framework to 1.1 in IIS msc tool in windows.

Hope this helps
Assistant Manager, Pharmacy Informatics
Wordpress Learning Blog
Updated : ASP.Net Login Code
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2
Reputation: phebe is an unknown quantity at this point 
Solved Threads: 0
phebe phebe is offline Offline
Newbie Poster

Re: Simple ASP.Net Login Page using C#

 
0
  #42
Oct 31st, 2006
Thank You very much
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 10
Reputation: GeniXmeN is an unknown quantity at this point 
Solved Threads: 0
GeniXmeN's Avatar
GeniXmeN GeniXmeN is offline Offline
Newbie Poster

Re: Simple ASP.Net Login Page using C#

 
0
  #43
Nov 1st, 2006
Thanks a lot Paladine but when i have make like you have write to me and have try something else i always get this error:
'Login1.WebForm1.test(string, string)': not all code paths return a value

the function is:
privatebool test(string txtUser,string txtPassword)
{
OleDbConnection myConn = new OleDbConnection(ConfigurationSettings.AppSettings["strCon"]);
OleDbCommand myCmd = new OleDbCommand("proverka",myConn);
myCmd.CommandType = CommandType.StoredProcedure;
OleDbParameter objParam1,objParam2;
//OleDbParameter returnParam;
objParam1 = myCmd.Parameters.Add("@UserName",OleDbType.Char);
objParam2 = myCmd.Parameters.Add("@Password",OleDbType.Char);
//returnParam = myCmd.Parameters.Add("@ID",OleDbType.Integer);
objParam1.Direction = ParameterDirection.Input;
objParam2.Direction = ParameterDirection.Input;
//returnParam.Direction = ParameterDirection.ReturnValue;
objParam1.Value = txtUser;
objParam2.Value = txtPassword;
 
try
{
if(myConn.State == ConnectionState.Closed)
{
myConn.Open();
//myCmd.ExecuteNonQuery();
}
OleDbDataReader objReader;
objReader = myCmd.ExecuteReader(CommandBehavior.CloseConnection);
while(objReader.Read())
{
if((bool)(objReader.GetValue(0)) == false)
{
Label1.Text="Inavlid Login!";
return false;
}
else
{
objReader.Close();
return true;
}
}
}
catch(Exception ex)
{
Label2.Text = ex + "Error connecting to the DB!";
return false;
}
}
Last edited by Paladine; Nov 1st, 2006 at 7:48 pm. Reason: code blocks!
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 10
Reputation: GeniXmeN is an unknown quantity at this point 
Solved Threads: 0
GeniXmeN's Avatar
GeniXmeN GeniXmeN is offline Offline
Newbie Poster

Re: Simple ASP.Net Login Page using C#

 
0
  #44
Nov 1st, 2006
I have and another question?

How to make when login is sucesiful and will open the page default.aspx to show me for example in textbox or label the first name and second name of the user normaly if in the DB we have information about that.
For example "Welcome John Jonson"
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 3
Reputation: kumarvp is an unknown quantity at this point 
Solved Threads: 0
kumarvp kumarvp is offline Offline
Newbie Poster

Re: Simple ASP.Net Login Page using C#

 
0
  #45
Feb 15th, 2007
hi! i was tested your code but i got an error..
i thing the error is in stored procedure...
pls send me the coding for stored procedure and table..
Reply With Quote Quick reply to this message  
Join Date: Feb 2003
Posts: 793
Reputation: Paladine has a spectacular aura about Paladine has a spectacular aura about Paladine has a spectacular aura about 
Solved Threads: 26
Team Colleague
Paladine's Avatar
Paladine Paladine is offline Offline
Master Poster

Re: Simple ASP.Net Login Page using C#

 
0
  #46
Feb 16th, 2007
Originally Posted by GeniXmeN View Post
Thanks a lot Paladine but when i have make like you have write to me and have try something else i always get this error:
'Login1.WebForm1.test(string, string)': not all code paths return a value

the function is:
privatebool test(string txtUser,string txtPassword)
{
OleDbConnection myConn = new OleDbConnection(ConfigurationSettings.AppSettings["strCon"]);
OleDbCommand myCmd = new OleDbCommand("proverka",myConn);
myCmd.CommandType = CommandType.StoredProcedure;
OleDbParameter objParam1,objParam2;
//OleDbParameter returnParam;
objParam1 = myCmd.Parameters.Add("@UserName",OleDbType.Char);
objParam2 = myCmd.Parameters.Add("@Password",OleDbType.Char);
//returnParam = myCmd.Parameters.Add("@ID",OleDbType.Integer);
objParam1.Direction = ParameterDirection.Input;
objParam2.Direction = ParameterDirection.Input;
//returnParam.Direction = ParameterDirection.ReturnValue;
objParam1.Value = txtUser;
objParam2.Value = txtPassword;
 
try
{
if(myConn.State == ConnectionState.Closed)
{
myConn.Open();
//myCmd.ExecuteNonQuery();
}
OleDbDataReader objReader;
objReader = myCmd.ExecuteReader(CommandBehavior.CloseConnection);
while(objReader.Read())
{
if((bool)(objReader.GetValue(0)) == false)
{
Label1.Text="Inavlid Login!";
return false;
}
else
{
objReader.Close();
return true;
}
}
}
catch(Exception ex)
{
Label2.Text = ex + "Error connecting to the DB!";
return false;
}
}
Your code with the brackets located above have me a little puzzled. Be sure you can go through each logic path and have a return value!
Assistant Manager, Pharmacy Informatics
Wordpress Learning Blog
Updated : ASP.Net Login Code
Reply With Quote Quick reply to this message  
Join Date: Feb 2003
Posts: 793
Reputation: Paladine has a spectacular aura about Paladine has a spectacular aura about Paladine has a spectacular aura about 
Solved Threads: 26
Team Colleague
Paladine's Avatar
Paladine Paladine is offline Offline
Master Poster

Re: Simple ASP.Net Login Page using C#

 
0
  #47
Feb 16th, 2007
Originally Posted by kumarvp View Post
hi! i was tested your code but i got an error..
i thing the error is in stored procedure...
pls send me the coding for stored procedure and table..
This is for ASP.NET 1.0 and 1.1 only, not 2.0 just as an FYI

Table
         CREATE TABLE NorthWindUsers 
             (UserID INT IDENTITY(1,1) NOT NULL,
              UserName VARCHAR(50) NOT NULL,
              Password VARCHAR(50) NOT NULL)
Stored Procedure in SQL 2000
         CREATE PROCEDURE sp_ValidateUser /* How it would appear in QUERY ANALYZER */
             (
                 @UserName VARCHAR(50) = NULL,
                 @Password VARCHAR(50) = NULL,
                 @Num_of_User INT = 0
             )
         AS
             SET @Num_of_User = (SELECT COUNT(*) AS Num_of_User
             FROM NorthWindUsers
             WHERE UserName = @UserName AND Password = @Password)
RETURN  @Num_of_User
Hope this helps

Assistant Manager, Pharmacy Informatics
Wordpress Learning Blog
Updated : ASP.Net Login Code
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 3
Reputation: kumarvp is an unknown quantity at this point 
Solved Threads: 0
kumarvp kumarvp is offline Offline
Newbie Poster

Re: Simple ASP.Net Login Page using C#

 
0
  #48
Feb 16th, 2007
hi paladine! thanks for ur reply..
my problem was, stored procedure always returns 0 only..
so i got invalid login name only....
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 1
Reputation: seshuv is an unknown quantity at this point 
Solved Threads: 0
seshuv seshuv is offline Offline
Newbie Poster

Re: Simple ASP.Net Login Page using C#

 
0
  #49
Feb 24th, 2007
Web.Config
[code]
]
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="strConn" value="Network Library=DBMSSOCN;Data Source=192.168.0.100,1433;database=Northwind;User id=;Password=;"/>
</appSettings>
<system.web>

<!-- DYNAMIC DEBUG COMPILATION
...


Me in a learner, i just copied and tried...im getting an error near
"strConn"..? what i must add there... may i know in a brief way... this is the one error im getting when im trying to run program..

Seshu
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 1
Reputation: maridhasm is an unknown quantity at this point 
Solved Threads: 0
maridhasm maridhasm is offline Offline
Newbie Poster

Re: Simple ASP.Net Login Page using C#

 
0
  #50
Feb 24th, 2007
hi
this is dos here,
your job doing great, still i haning a course .net in c#. now what i need from your guys, just give simple console application mini project or ideas for that relative environment. than you.
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC