C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Form Authentication


Posted Date: 19 Aug 2004    Resource Type: Articles    Category: .NET Framework

Posted By: maladhamodaran       Member Level: Gold
Rating:     Points: 10



Form Authentication
Form authentication uses cookies to authenticate users and allows the application to do its own credential verification.Using this provider causes unauthenticated requests to be redirected to a specified HTML form using client side redirection.

Forms Authentication Setup

Pages Included : Web.config, Default.aspx, Login.aspx.

Table:
create a login table in Sqlserver with columns, login name and password.Insert values in the table.

Web.config Page
The Web.config contains all of the configuration settings for an ASP.NET application.


< authentication mode="Forms">
< forms name="cook" protection="All" loginUrl="login.aspx" timeout="30" path="/"/>
/authentication>

< authorization>
< deny users="?"/>
< /authorization>


here
- cook is the name of the cookie used for authentication.
- Path is the Path used for cookie."/" is the default path.
- loginUrl is the URL that unauthenticated users are redirected to.
- Protection is Method used to protect cookie data.The value can beDefault or All.Suggested value is "All," which does validation and encryption.
- Timeout is the Number of minutes until authentication cookie expires.

In the authorization section, we want to ensure that no unauthenticated users can access the application. The "?" means anonymous users, so we set a deny flag for all anonymous users.


Login.aspx Page:

< form id="Form1" method="post" runat="server">
< asp:TextBox id="user" runat="server" Width="161px" Height="33px"/>
< asp:TextBox id="pwd" runat="server" Width="163px" Height="36px"/>
< asp:Button id="submit" runat="server" Width="78px" Height="43px" Text="Button"/>
< /form>

//declare the required variable

private void submit_Click(object sender, System.EventArgs e)
{
cn = new SqlConnection("server=pushpa;database=leela;uid=sa;pwd=sql");
cmd = new SqlCommand("Select name,password from login",cn);
cn.Open();
dr = cmd.ExecuteReader();
while (dr.Read())
{

if((dr.GetString (0)== user.Text )&&(dr.GetString(1)== pwd.Text ))
{
FormsAuthentication.RedirectFromLoginPage(user.Text,true);
Response.Redirect("default.aspx");
}
}

}

We can use a button to signout from form authentication and redirect to the login page.

FormsAuthentication.SignOut();
Response.Redirect("logon.aspx");

default.aspx
If the user is a valid user then the user is redirected to the default page.





Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Form Authentication  .  Authentication  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Web Farm
Previous Resource: Some tips to improve your UI #2
Return to Discussion Resource Index
Post New Resource
Category: .NET Framework


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

silicone halloween masks

Contact Us    Privacy Policy    Terms Of Use