SlideShare una empresa de Scribd logo
1 de 5
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
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
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
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
 
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

Más contenido relacionado

La actualidad más candente

Automation anywhere user manual tethys solutions
Automation anywhere user manual   tethys solutionsAutomation anywhere user manual   tethys solutions
Automation anywhere user manual tethys solutions
Vijay Reddy
 
Visualforce controllers
Visualforce controllersVisualforce controllers
Visualforce controllers
Amit Sharma
 
Getting started-with-oracle-so a-9
Getting started-with-oracle-so a-9Getting started-with-oracle-so a-9
Getting started-with-oracle-so a-9
Amit Sharma
 

La actualidad más candente (20)

Web testing
Web testingWeb testing
Web testing
 
Automation anywhere user manual tethys solutions
Automation anywhere user manual   tethys solutionsAutomation anywhere user manual   tethys solutions
Automation anywhere user manual tethys solutions
 
M365 global developer bootcamp 2019
M365 global developer bootcamp 2019M365 global developer bootcamp 2019
M365 global developer bootcamp 2019
 
Lecture 12: React-Native Firebase Authentication
Lecture 12: React-Native Firebase AuthenticationLecture 12: React-Native Firebase Authentication
Lecture 12: React-Native Firebase Authentication
 
Visualforce controllers
Visualforce controllersVisualforce controllers
Visualforce controllers
 
Asp.net w3schools
Asp.net w3schoolsAsp.net w3schools
Asp.net w3schools
 
How to embed forms on your blog
How to embed forms on your blogHow to embed forms on your blog
How to embed forms on your blog
 
Diff sand box and farm
Diff sand box and farmDiff sand box and farm
Diff sand box and farm
 
Keyword Driven Testing
Keyword Driven TestingKeyword Driven Testing
Keyword Driven Testing
 
C# with Renas
C# with RenasC# with Renas
C# with Renas
 
Details Description of Load Runner Recording option
Details Description of  Load Runner Recording optionDetails Description of  Load Runner Recording option
Details Description of Load Runner Recording option
 
M365 global developer bootcamp 2019 Intro to SPFx Version
M365 global developer bootcamp 2019 Intro to SPFx VersionM365 global developer bootcamp 2019 Intro to SPFx Version
M365 global developer bootcamp 2019 Intro to SPFx Version
 
Securing api with_o_auth2
Securing api with_o_auth2Securing api with_o_auth2
Securing api with_o_auth2
 
Web works hol
Web works holWeb works hol
Web works hol
 
Keyword driven testing in qtp
Keyword driven testing in qtpKeyword driven testing in qtp
Keyword driven testing in qtp
 
V mware view 4
V mware view 4V mware view 4
V mware view 4
 
Implementing auto complete using JQuery
Implementing auto complete using JQueryImplementing auto complete using JQuery
Implementing auto complete using JQuery
 
Getting started-with-oracle-so a-9
Getting started-with-oracle-so a-9Getting started-with-oracle-so a-9
Getting started-with-oracle-so a-9
 
Tutorial 1
Tutorial 1Tutorial 1
Tutorial 1
 
Alcim wp training 26 may
Alcim wp training 26 mayAlcim wp training 26 may
Alcim wp training 26 may
 

Destacado (6)

Bjfogg Aarp
Bjfogg AarpBjfogg Aarp
Bjfogg Aarp
 
Stream upload and asynchronous job processing in large scale systems
Stream upload and asynchronous job processing  in large scale systemsStream upload and asynchronous job processing  in large scale systems
Stream upload and asynchronous job processing in large scale systems
 
Inside Zalo: Developing a mobile messenger for the audience of millions
Inside Zalo: Developing a mobile messenger for the audience of millionsInside Zalo: Developing a mobile messenger for the audience of millions
Inside Zalo: Developing a mobile messenger for the audience of millions
 
Zing Me Real Time Web Chat Architect
Zing Me Real Time Web Chat ArchitectZing Me Real Time Web Chat Architect
Zing Me Real Time Web Chat Architect
 
Inside Zalo: Developing a mobile messenger for the audience of millions - VN ...
Inside Zalo: Developing a mobile messenger for the audience of millions - VN ...Inside Zalo: Developing a mobile messenger for the audience of millions - VN ...
Inside Zalo: Developing a mobile messenger for the audience of millions - VN ...
 
Inside Zalo: Developing a mobile messenger for the audience of millions - VN ...
Inside Zalo: Developing a mobile messenger for the audience of millions - VN ...Inside Zalo: Developing a mobile messenger for the audience of millions - VN ...
Inside Zalo: Developing a mobile messenger for the audience of millions - VN ...
 

Similar a C Sharp Cornerarticle

Code Camp Applying Modern Software Development Techniques To Ui Testing
Code Camp  Applying Modern Software Development Techniques To Ui TestingCode Camp  Applying Modern Software Development Techniques To Ui Testing
Code Camp Applying Modern Software Development Techniques To Ui Testing
ChristopherGTaylor
 
5a329780735625624 ch10
5a329780735625624 ch105a329780735625624 ch10
5a329780735625624 ch10
harkesh singh
 
STARWEST 2011 - 7 Steps To Improving Software Quality using Microsoft Test Ma...
STARWEST 2011 - 7 Steps To Improving Software Quality using Microsoft Test Ma...STARWEST 2011 - 7 Steps To Improving Software Quality using Microsoft Test Ma...
STARWEST 2011 - 7 Steps To Improving Software Quality using Microsoft Test Ma...
Anna Russo
 
STARWEST 2010 - 7 Steps To Improving Software Quality using Microsoft Test Ma...
STARWEST 2010 - 7 Steps To Improving Software Quality using Microsoft Test Ma...STARWEST 2010 - 7 Steps To Improving Software Quality using Microsoft Test Ma...
STARWEST 2010 - 7 Steps To Improving Software Quality using Microsoft Test Ma...
Anna Russo
 
STAREAST 2011 - 7 Steps To Improving Software Quality using Microsoft Test Ma...
STAREAST 2011 - 7 Steps To Improving Software Quality using Microsoft Test Ma...STAREAST 2011 - 7 Steps To Improving Software Quality using Microsoft Test Ma...
STAREAST 2011 - 7 Steps To Improving Software Quality using Microsoft Test Ma...
Anna Russo
 

Similar a C Sharp Cornerarticle (20)

Code Camp Applying Modern Software Development Techniques To Ui Testing
Code Camp  Applying Modern Software Development Techniques To Ui TestingCode Camp  Applying Modern Software Development Techniques To Ui Testing
Code Camp Applying Modern Software Development Techniques To Ui Testing
 
UiPath Task Capture training.pdf
UiPath Task Capture training.pdfUiPath Task Capture training.pdf
UiPath Task Capture training.pdf
 
5a329780735625624 ch10
5a329780735625624 ch105a329780735625624 ch10
5a329780735625624 ch10
 
STARWEST 2011 - 7 Steps To Improving Software Quality using Microsoft Test Ma...
STARWEST 2011 - 7 Steps To Improving Software Quality using Microsoft Test Ma...STARWEST 2011 - 7 Steps To Improving Software Quality using Microsoft Test Ma...
STARWEST 2011 - 7 Steps To Improving Software Quality using Microsoft Test Ma...
 
Online banking
Online bankingOnline banking
Online banking
 
Installation of Silk Test Framework
Installation of Silk Test FrameworkInstallation of Silk Test Framework
Installation of Silk Test Framework
 
FlexNet Delivery and FlexNet Operations On-Demand Tips & Tricks
FlexNet Delivery and FlexNet Operations On-Demand Tips & TricksFlexNet Delivery and FlexNet Operations On-Demand Tips & Tricks
FlexNet Delivery and FlexNet Operations On-Demand Tips & Tricks
 
IBM Connect 2014 - SHOW501: Mastering Social Development Using the IBM Collab...
IBM Connect 2014 - SHOW501: Mastering Social Development Using the IBM Collab...IBM Connect 2014 - SHOW501: Mastering Social Development Using the IBM Collab...
IBM Connect 2014 - SHOW501: Mastering Social Development Using the IBM Collab...
 
IBM Connect 2014 SHOW501 Mastering Social Development Using the IBM Collabora...
IBM Connect 2014 SHOW501 Mastering Social Development Using the IBM Collabora...IBM Connect 2014 SHOW501 Mastering Social Development Using the IBM Collabora...
IBM Connect 2014 SHOW501 Mastering Social Development Using the IBM Collabora...
 
WebTest - Efficient Functional Web Testing with HtmlUnit and Beyond
WebTest - Efficient Functional Web Testing with HtmlUnit and BeyondWebTest - Efficient Functional Web Testing with HtmlUnit and Beyond
WebTest - Efficient Functional Web Testing with HtmlUnit and Beyond
 
Php[tek] 2016 - BDD with Behat for Beginners
Php[tek] 2016 - BDD with Behat for BeginnersPhp[tek] 2016 - BDD with Behat for Beginners
Php[tek] 2016 - BDD with Behat for Beginners
 
User Interface Testing. What is UI Testing and Why it is so important?
User Interface Testing. What is UI Testing and Why it is so important?User Interface Testing. What is UI Testing and Why it is so important?
User Interface Testing. What is UI Testing and Why it is so important?
 
Automated Build using teamcity
Automated Build using teamcityAutomated Build using teamcity
Automated Build using teamcity
 
MAX 2008 - Building your 1st AIR application
MAX 2008 - Building your 1st AIR applicationMAX 2008 - Building your 1st AIR application
MAX 2008 - Building your 1st AIR application
 
STARWEST 2010 - 7 Steps To Improving Software Quality using Microsoft Test Ma...
STARWEST 2010 - 7 Steps To Improving Software Quality using Microsoft Test Ma...STARWEST 2010 - 7 Steps To Improving Software Quality using Microsoft Test Ma...
STARWEST 2010 - 7 Steps To Improving Software Quality using Microsoft Test Ma...
 
ASP.NET MVC3 RAD
ASP.NET MVC3 RADASP.NET MVC3 RAD
ASP.NET MVC3 RAD
 
Resume-Updated
Resume-Updated Resume-Updated
Resume-Updated
 
Module 4: Introduction to ASP.NET 3.5 (Material)
Module 4: Introduction to ASP.NET 3.5 (Material)Module 4: Introduction to ASP.NET 3.5 (Material)
Module 4: Introduction to ASP.NET 3.5 (Material)
 
STAREAST 2011 - 7 Steps To Improving Software Quality using Microsoft Test Ma...
STAREAST 2011 - 7 Steps To Improving Software Quality using Microsoft Test Ma...STAREAST 2011 - 7 Steps To Improving Software Quality using Microsoft Test Ma...
STAREAST 2011 - 7 Steps To Improving Software Quality using Microsoft Test Ma...
 
Execute Automation Testing in 3 Steps
Execute Automation Testing in 3 StepsExecute Automation Testing in 3 Steps
Execute Automation Testing in 3 Steps
 

Último

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Último (20)

Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 

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