Weitere ähnliche Inhalte
Ähnlich wie C Sharp Cornerarticle (20)
Kürzlich hochgeladen (20)
C Sharp Cornerarticle
- 1. How to use Login Control in Visual Studio 2005 Author Rank:
Technologies: .NET 1.0/1.1, ASP.NET 1.0,
Controls,Visual Studio 2005
By Sushmita Kumari January 31, 2006
Total downloads : 165
Total page views : 12343
In the recent version of Visual Studio 2005, Microsoft has taken care of a very common functionality of the Rating : 2/5
web applications. In the following article we will see that how to use login control using C#.Net. This article has been rated : 1 times
Download Files:
This Article is sponsored by:
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to
dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your
applications.
Simply the fastest line-level profiler for .NET ever
Even when ANTS Profiler 4 is collecting line-level timings, the overhead is hardly noticeable” Geoff Hirst, 64Bitz CC Ltd. Try out the
new ANTS Profiler 4 for yourself, download your 14-day trial now.
Go.NET
Build custom interactive diagrams, network, workflow editors, flowcharts, or software design tools. Includes many predefined kinds of
nodes, links, and basic shapes. Supports layers, scrolling, zooming, selection, drag-and-drop, clipboard, in-place editing, tooltips, grids,
printing, overview window, palette. 100% implemented in C# as a managed .NET Control. Document/View/Tool architecture with
many properties&events. Optional automatic layout.
Dundas Software
Dundas Chart for .NET is the most advanced .NET charting package available today. With an extremely complete feature set, elegant
architecture and easy implementation, Dundas Chart can quickly add advanced Charting functionality to enhance and transform
ASP.NET and Windows Forms applications. Whether you are implementing charting into internal projects, or building applications for
clients, Dundas Chart offers advanced technology and advanced results to get the most out of data.
ExpertPDF
ExpertPDF is a .NET library that offers the possibility to convert your HTML pages to PDF on the fly. If you need PDF reports you don't
have to use complex report generators anymore. Just create a simple ASP.NET page and export it to PDF with ExpertPDF HtmlToPdf
Converter.
Microsoft® Visual Studio 2008
Got an ogre to defeat? Visual Studio has the latest tools you need. New tools for Microsoft Office 2007, AJAX controls, and Team
System.
As a web developer we know that most of the time our application is having a login as well as the forget password kind of requirement.
Now, using visual studio 2005 it's very easy to design a login page because the inbuilt login tab has been added into the toolbox of VS
2005 editor, which has different types of control related to login functional.
© 2008 C# Corner and Authors. page 1 / 5
- 2. Fig 1.1: New tab for login
Fig 1.2: All the controls of Login Tab
In the following article we will see that how to use login control using C#.Net. The following code will explain that how to authenticate
the user against the database.
Step 1:- Drag and drop the login control on the page then the control will look like a login page at design time.
© 2008 C# Corner and Authors. page 2 / 5
Fig 1.3: Login control at design time
- 3. Fig 1.3: Login control at design time
Step 2: Once the UI is ready then will go ahead with the coding part to see how to write the code for this control.
To write the code for this code we need to handle the Login1_Authenticate event.
So, double click on the Login control it will generate the following code:-
protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
{
bool Authenticated = false;
Authenticated = SiteLevelCustomAuthenticationMethod(Login1.UserName, Login1.Password);
e.Authenticated = Authenticated;
if (Authenticated == true)
{
Response.Redirect(quot;Home.aspxquot;);
}
}
private bool SiteLevelCustomAuthenticationMethod(string UserName, string Password)
{
bool boolReturnValue = false;
// Insert code that implements a site-specific custom
// authentication method here.
// This example implementation always returns false.
string strConnection = quot;server=dtpxp-skumari;database=master;uid=sa;pwd=;quot;;
SqlConnection Connection = new SqlConnection(strConnection);
String strSQL = quot;Select * From Employeequot;;
SqlCommand command =new SqlCommand(strSQL, Connection);
SqlDataReader Dr;
Connection.Open();
Dr=command.ExecuteReader();
while (Dr.Read())
{
if ((UserName == Dr[quot;namequot;].ToString()) & (Password == Dr[quot;Passwordquot;].ToString()))
{
boolReturnValue = true;
}
Dr.Close();
return boolReturnValue;
}
}
Login control is having a property called FailureText where you can write your own message.
Fig 1.4: Custom Error Message
Once you have passed the correct login credential then you will be redirected to the home page using the DestinationPageUrl property.
DestinationPageUrl is the property of login control which is used to redirect the user to desination page after a successful login. If
incorrect login credential it will show the message like quot;Your login attempt was not successful. Please try againquot;. This is a custom
message specified by the user through the FailureText property.
© 2008 C# Corner and Authors. page 3 / 5
- 4. Once you have passed the correct login credential then you will be redirected to the home page using the DestinationPageUrl property.
DestinationPageUrl is the property of login control which is used to redirect the user to desination page after a successful login. If
incorrect login credential it will show the message like quot;Your login attempt was not successful. Please try againquot;. This is a custom
message specified by the user through the FailureText property.
Fig 1.5: Logion Error
About inbuilt validation:- Login control is having a inbuilt validation feature which is available as a property for programmer. When you
will drag-drop the control at design time you will see that the username and password textboxes are marked with star (*) sign which
means these fields are required fields.
Fig 1.6: Validation
Login control is having some more features like specifying .CSS property, Button style etc.
Steps to use the sample:-
© 2008 C# Corner and Authors. page 4 / 5
1. Download a zip file --> Unzip the file
2. Go to Start-->RUN-->inetmgr.exe
- 5.
Steps to use the sample:-
1. Download a zip file --> Unzip the file
2. Go to Start-->RUN-->inetmgr.exe
3. Go to Websites-->Default web sites
4. Right click on it-->NewVirtual Directory-->it will start the wizard
5. Map the unzip folder with the virtual directory-->finish
6. Run the application/Open the solution file.
More Similar Articles
About the author
Sushmita Kumari
This article is converted to PDF using Expert PDF. Click here for a free download.
© 2008 C# Corner and Authors. page 5 / 5