In this article, I'm going to explain how to set Windows Authentication to configure ASP.NET application in IIS. To make Windows authorize application you need to make changes in web.config as well as IIS manager.

Configuring Windows Authentication

<system.web>
   <authentication mode="Windows"/>
</system.web>

  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.

If you will put Anonymous check box checked then it will not take windows login Id for the user. e.g. string windowsLogin = Page.User.Identity.Name;

Now, your application will work on windows authentication.

Here is the example code:

protected void Page_Load(object sender, EventArgs e)
{
   try
     {
       //Start:
        if (Session["EmployeeCode"] == null)
          {
             string windowsLogin = Page.User.Identity.Name;
             //Check user is valid or not from data base
            //I am putting simple condition by hard code value
            if (windowsLogin=='ValidUser')
                 {
                   Session["EmployeeCode"] = userId;
                 }
             else
                {
                  Session.Abandon();
                  Response.Redirect("InvalidUser.aspx", false);
                }
         //End
     }
    catch (Exception ex)
    {
       //Handel exception here
       Throw;
     }
}

It's done! You will get user from windows credential and check with existing user with database. If user is valid go ahead other wise navigate the user to Invalid page.

HostForLIFE.eu IIS 8.0 Hosting
HostForLIFE.eu is European Windows Hosting Provider which focuses on Windows Platform only. We deliver on-demand hosting solutions including Shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes. We have customers from around the globe, spread across every continent. We serve the hosting needs of the business and professional, government and nonprofit, entertainment and personal use market segments.