Authentication
Authentication answers “who is this user?”. IIS can authenticate users before the request even reaches your app.
On this page · 5 min · Intermediate
On this page
- In simple words
- Learning objectives
- Explanation
- Code example
- Step by step
- Real-world use
- Common mistakes
- Best practices
- Remember this
- Practice exercise
- Mini quiz
- Related topics
- My notes
- Reading time
- 5 min
- Difficulty
- Intermediate
- Updated
- Oct 30, 2026
Related tutorials
Interview questions
In simple words#
Anonymous is an open museum — anyone can walk in. Windows authentication is a company office where your employee badge opens the door automatically. Basic authentication is a guard asking for your username and password at the door (only safe if the conversation is private — HTTPS).
- Anonymous
- No login; IIS uses IUSR or the pool identity.
- Windows authentication
- Domain users signed in automatically (Kerberos/NTLM).
- 401.2
- Error when no enabled method matches.
Learning objectives#
- Enable and disable authentication methods
- Configure Windows authentication for intranet apps
- Use authentication in ASP.NET Core
- Avoid insecure Basic authentication
Explanation#
Each site or application chooses which methods are enabled. Public sites: Anonymous only. Intranet: Windows authentication, Anonymous disabled.
Windows authentication uses Kerberos or NTLM; domain users in Edge/Chrome sign in without typing passwords.
In ASP.NET Core, IIS passes the Windows user to the app: builder.Services.AddAuthentication(IISDefaults.AuthenticationScheme) and [Authorize].
Basic authentication sends credentials in every request (Base64, not encrypted) — only ever over HTTPS, and preferably not at all.
Code example: Intranet site with Windows authentication#
# Authentication sections are locked at server level, so set them for the site in applicationHost.config
Set-WebConfigurationProperty -PSPath "MACHINE/WEBROOT/APPHOST" -Location "HrPortal" `
-Filter "system.webServer/security/authentication/anonymousAuthentication" -Name enabled -Value $false
Set-WebConfigurationProperty -PSPath "MACHINE/WEBROOT/APPHOST" -Location "HrPortal" `
-Filter "system.webServer/security/authentication/windowsAuthentication" -Name enabled -Value $true
# ASP.NET Core (Program.cs):
# builder.Services.AddAuthentication(Microsoft.AspNetCore.Server.IISIntegration.IISDefaults.AuthenticationScheme);
# builder.Services.AddAuthorization();
# app.UseAuthentication(); app.UseAuthorization();
# In a controller: User.Identity.Name → "CORP\asha"
Employees open https://hr.corp.example and are signed in automatically; the app sees User.Identity.Name = CORP\asha.
This example is illustrative. Copy or download it and run it in your own environment; the expected output is shown above.
Step-by-step explanation#
- Anonymous authentication is disabled for the site.
- Windows authentication is enabled.
- The setting is stored per site in applicationHost.config because the section is locked.
- ASP.NET Core reads the Windows identity through IIS integration.
Real-world use case#
An internal leave-management portal uses Windows authentication so staff never create separate passwords.
Common mistakes#
Anonymous wins for requests that don’t require auth. Disable Anonymous or use [Authorize] everywhere.
Passwords travel almost in plain text. Always HTTPS — prefer Windows or token-based auth.
Best practices#
- Anonymous for public sites
- Windows auth for intranet apps
- HTTPS for any credential exchange
- Combine with authorization rules or [Authorize]
Remember this#
Anonymous = public. Windows = domain badge.
Basic only over HTTPS (better: avoid).
401.2 = no allowed auth method succeeded.
Practice exercise#
Your task: Where would you check if a domain user gets prompted for a password instead of signing in automatically?
Show solution
The site must be in the browser’s Local intranet zone (or allowed list), Windows auth must use Negotiate, and the SPN must be correct for Kerberos.
Mini quiz#
Which method signs domain users in automatically on an intranet?
Want more? Practise all IIS MCQs · IIS interview questions
My notes#
Saved in this browser.