ASP.NET - Implementing windows authentication - Asked By Anandh Ramanujam on 17-Mar-11 06:39 AM

Hi,

Anybody giving me the sample, how to validate the users enter to the asp.net application using windows authentication.. Please provide me the complete process and sample code.. Im very new to this one...

thanks.
Reena Jain replied to Anandh Ramanujam on 17-Mar-11 06:44 AM
hi,

To configure your application to use Integrated Windows authentication, you must use IIS Manager to configure your application's virtual directory security settings and you must configure the <authentication> element in the Web.config file.

To configure Windows authentication

  1. Start Internet Information Services (IIS).
  2. Right-click your application's virtual directory, and then click Properties.
  3. Click the Directory Security tab.
  4. Under Anonymous access and authentication control, click Edit.
  5. Make sure the Anonymous access check box is not selected and that Integrated Windows authentication is the only selected check box.

In your application's Web.config file or in the machine-level Web.config file, ensure that the authentication mode is set to Windows as shown here.

<system.web>
 ...
 <authentication mode="Windows"/>
 ...
</system.web>
hope this will help you
Anandh Ramanujam replied to Reena Jain on 17-Mar-11 06:57 AM
anything need to be code in login page code behind file?? To check against the users credentials.
sandeep kumar replied to Reena Jain on 17-Mar-11 06:58 AM

Configuring Windows Authentication

To configure your application to use Integrated Windows authentication, you must use IIS Manager to configure your application's virtual directory security settings and you must configure the <authentication> element in the Web.config file.

To configure Windows authentication

  1. Start Internet Information Services (IIS).
  2. Right-click your application's virtual directory, and then click Properties.
  3. Click the Directory Security tab.
  4. Under Anonymous access and authentication control, click Edit.
  5. Make sure the Anonymous access check box is not selected and that Integrated Windows authentication is the only selected check box.

In your application's Web.config file or in the machine-level Web.config file, ensure that the authentication mode is set to Windows as shown here.

...
 <system.web>
  ...
  <authentication mode="Windows"/>
  ...
 </system.web>
 ...
  
Reena Jain replied to Anandh Ramanujam on 17-Mar-11 07:02 AM
hi,

you can get the user name from the System.Web.HttpContext.Current.User.Identity.Name only after the user login to the system, here is the code for you

private void btnLogin_Click(object sender, System.EventArgs e)
{   
 
bool bResult = false;
string strUserName = txtUserName.Text.ToString();
string strPassword = txtPassword.Text.ToString();    
 
if (Membership.ValidateUser(strUserName, strPassword))    
 
{   // Valid User so check if they are in CRDB as well as not being disabled      
 
MembershipUser mu = Membership.GetUser(strUserName);          
e.Authenticated = true;          
base.User_TpxId = Login1.UserName;          
base.User_FirstName = dbUser.FirstName;           
base.User_LastName = dbUser.LastName;          
FormsAuthentication.RedirectFromLoginPage(Login1.UserName, false);
}     
else    
{      
MembershipUser mu = Membership.GetUser(strUserName);      
if (mu == null)        
 Login1.FailureText = "You do not appear to have been setup in Active Directory. Please contact an Administrator";      
else        
Login1.FailureText = "Your password does not appear to be correct.";      
e.Authenticated = false;    
}  
}

Hope this will help  you