forms authentication forms authentication

How quickly, I can set forms authentication to allow access for only one user!

In web.config authentication section you need to add below code

<authentication mode="Forms">
   <forms defaultUrl="~/accounts/authuser.aspx" loginUrl="login.aspx" slidingExpiration="true" >
     <user name="admin" password="password"></user>

You can see here I have added credentials tag and added admin user their with password as password.

Now, I will let him login to system useing below code

        if(!FormsAuthentication.Authenticate( txtUserName.Text , txtPassword.Text ))
            // FormsAuthentication.SetAuthCookie( txtUserName.Text, true);

FormsAuthentication.Authonticate will validate the user against Forms credentials stored in web.config file.

If user is not valid, you can redirect him back to LoginPage


It will redirect the user from login page to authorised page and it will set authontication cookie at client side browser.


Tags: 2.0 step by step Membership Provider Interview Questions for 2 years or 3 years experianceasp net image File HandlingWhat is web garden in Convert String To Convert Image To open new windowHack How To Write a Cookie and Read


My name is Satalaj, but people call me Sat. Here is my homepage: . I live in Pune, PN and work as a Software Engineer. I'm former MVP in year 2010.
Disclaimer: Views or opinion expressed here are my personal research and it has nothing to do with my employer. You are free to use the code, ideas/hints in your projects. However, you should not copy and paste my original content to other web sites. Feel free to copy or extend the code.
If you want to fight with me, this website is not for you.

I'm Satalaj.