Home > DeveloperSection > Forums > Forms Authentication and Authorization
Carl Pieterson
Carl Pieterson

Total Post:14

Points:98
Posted on    September-20-2011 1:02 AM

 ASP.Net ASP.Net 
Ratings:


 2 Reply(s)
 1734  View(s)
Rate this:

How to use Forms Authentication and Authorization in ASP.NET?



Chris Anderson
Chris Anderson

Total Post:65

Points:455
Posted on    September-20-2011 1:34 AM

In order to acheive your result first you have to write the some code in web.config file:

<system.web>
       <authentication mode="Forms">
          <forms loginUrl="login.aspx" defaultUrl="Employee.aspx" />
       </authentication>

       <authorization>
          <allow users="aaa"/>
          <allow users="bbb"/>
          <deny users="*"/>
        </authorization>
</system.web>

Then you have to authenticate and authorized the user based on the user available in authorization part:

string strId = Login1.UserName;
string strPass = Login1.Password;
if (strId == "aaa" && strPass == "aaa")
     FormsAuthentication.RedirectFromLoginPage(strId, false);
else
     Login1.FailureText = "Invalid ID or Password";

Thanks.


Modified On Sep-20-2011 01:35:31 AM

Carl Pieterson
Carl Pieterson

Total Post:14

Points:98
Posted on    September-20-2011 1:37 AM

Thanks Rohit for answering me.

Modified On Sep-20-2011 09:36:36 AM

Don't want to miss updates? Please click the below button!

Follow MindStick