Hi All,
To use form authentication in asp.net application
1- Create a new website
2- Change the name of the default.aspx to login.aspx
3- Add 2 labels one for username and password and two textboxes name txtUserName and txtPassword
and a button named btnLogin with label Login.
4 -Put the following in the web.config page
<authentication mode=”Forms”>
<forms loginUrl=”login.aspx”>
<credentials passwordFormat=”Clear”>
<user name=”Mickey” password=”Mouse”/>
</credentials>
</forms>
</authentication>
<authorization>
<deny users=”?”/>
</authorization>
5-Put this code in the btnLogin click’s event handler.
protected void btnLogin_Click(object sender, EventArgs e)
{
if(FormsAuthentication.Authenticate(txtUserName.Text,txtPassword.Text))
{
FormsAuthentication.RedirectFromLoginPage(txtUserName.Text, false);
}
else
{
lblInfo.Text = “you are not authorized to view the page”; // add one more label lblInfo }
}
6- That’s it your page should work now
We can add more users within the credential section of web.config
We can even encrypt the password we are saving in the web.config
We can even make use of cookie for the same.
Looking forward to include the code for the same
Bye
Discover more from Nishant Rana's Weblog
Subscribe to get the latest posts sent to your email.

Hi nishant
I really liked your web site and inforamtion provided in a very simple manner. I look forward to see the updates frequently and keep up the good work.
Thanks
Hemant Rojinedar (s/w consultant .net/oracle areas)
LikeLike
Thanks Hemant for your encouragement and appreciation.
LikeLike