ExpertRating - Online Certification and Employment Testing ExpertRating - Online Certification and Employment Testing ExpertRating - Online Certification and Employment Testing

ExpertRating Home
ExpertRating Benefits
Recommend ExpertRating
Suggest More Tests
Privacy Policy
FAQ
Login
 
ASP Dot Net Tutorial - Index
ASP Dot Net Tutorial - Microsofts ASP.NET
ASP Dot Net Tutorial - Begining Web Forms
ASP Dot Net Tutorial - User Controls
ASP Dot Net Tutorial - ADO .NET
ASP Dot Net Tutorial - DataBinding to WebControls
ASP Dot Net Tutorial - DataList Controls
ASP Dot Net Tutorial - DataGrid Control
ASP Dot Net Tutorial - Advance Practical Examples on DataGrid
ASP Dot Net Tutorial - Working with DataSets
ASP Dot Net Tutorial - Working with XML
ASP Dot Net Tutorial - Forms Based Authentication
ASP Dot Net Tutorial - Windows Based Authentication
     

 
Online Personal Trainer Certification
Test Search by Job Title
Find a Personal Trainer
Job Resources
Free Self Tests and Quizzes
Find a Lawyer
Project Management Certification
Six Sigma Certification
Six Sigma Black Belt Certification
Six Sigma Green Belt Certification
Lean Management Certification
First Aid Certification
CPR Certification
Yoga Certification
Aerobics Certification
Pilates Certification
SEO Certification
Online Photography Course & Certification
Online Business Writing Course & Certification
Baby Sitting Course & Certification
Time Manangement Certification
Health Club Management Certification
Selling Skills Certification
Business Analysis Course
Green Living Course  free!
Master Trainer Certification
Total Quality Management Certification
Kaizen Certification
Creative Writing Certification
  All Online Courses
   

   
   
   
   
   
   

   
  Home > Courses, Tutorials & eBooks > ASP.NET Tutorial > Forms-Based Authentication
 

ASP.NET Tutorial - Forms-Based Authentication

                                                                                                            Page 2 of 3
 

The Web.Config file in the above example denies access to the ASP.NET pages contained in the directory to anonymous users. The ? symbol represents all anonymous users.

After the tile Web. Config file is added in Example 62to a directory, anonymous users are denied access to ASP.NET pages in that directory and all subdirectories. If you want to enable users to access tiles in a particular subdirectory, you can add the Web.Confiig file contained in Example 63.

 

Example 63 SimpleForns\Anon\Web.Config

< configuration >

< system.web >

< authorization >

< allow users ="?" />

</ authorization >

</ system.web >

</ configuration >

 

  The Web. Confiig file in Example 63allows all anonymous users to access any page contained in a directory and all the subdirectories of that directory.

The final step required for enabling Forms authentication is to create the Login. aspx page. If you attempt to access an ASP.NET page in a password-protected directory and you do not have the proper Authentication Ticket cookie, you are automatically redirected to this page.

The simple Login. aspx page contained in Example 64 displays a form with a field for a username and password (as shown below). The page requires you to enter the username Sam and password Secret. (The form is case-sensitive.)

 

Example 64 SimpleForm\login.aspx

<Script Runat="Server">

Sub Button_Click( s As Object, e As EventArgs )

If IsValid Then

If txtUsername.Text = "expert" And txtPassword.Text = "Secret" Then

FormsAuthentication.RedirectFromLoginPage(txtUsername.Text, chkRemember.Checked )

Else

lblMessage.Text = "Wrong username/password!"

End If

End If

End Sub

</Script>

<html>

<head><title>LoginPage</title></head>

<body>

<form Runat="Server">

<h2>Please Enter Your Login:</h2>

<asp:Label

ID="lblMessage"

ForeColor="Red"

Font-Bold="True"

Runat="Server" />

<p>

<b>Username:</b>

<br>

<asp:TextBox

ID="txtUsername"

Runat="Server" />

<asp:RequiredFieldValidator

ControlToValidate="txtUsername"

Text="Required!"

Runat="Server" />

<p>

<b>Password:</b>

<br>

<asp:TextBox

ID="txtPassword"

TextMode="password" Runat="Server" />

<asp:RequiredFieldValidator

ControlToValidate="txtPassword"

Text="Required!"

Runat="Server" />

<p>

<asp:CheckBox

ID="chkRemember"

Runat="Server"/>

Remember me with a cookie?

<p>

<asp:Button

Text="Login!"

OnClick="Button_Click"

Runat="Server" />

</form>

</body>

</html>

 


       
 

 

 

 
     
Home  |  About Us  |  Privacy Policy  |  Site Map  |  FAQs  |  Contact Us
 
© ExpertRating 2006. All Rights Reserved.