Cấu hình trên Powershell
Trong ví dụ này, Cấu hình cài đặt tạo thư mục [auth_basic] trong trang web [RX-7.srv.world] và đặt Basic Authentication cho Thư mục.
Mở Powershell và chạy với quyền quản trị là Admin.
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.
# install Basic Authentication feature
PS C:\Users\Administrator> Install-WindowsFeature Web-Basic-Auth
Success Restart Needed Exit Code Feature Result
------- -------------- --------- --------------
True No Success {Basic Authentication}
# restart IIS
PS C:\Users\Administrator> Restart-Service W3SVC
PS C:\Users\Administrator> Get-Website
Name ID State Physical Path Bindings
---- -- ----- ------------- --------
Default Web Site 1 Started %SystemDrive%\inetpub\wwwroot http *:80:
RX-7.srv.world 2 Started C:\inetpub\newsite http *:80:RX-7.srv.world
https *:443:rx-7.srv.world sslFlags=0
# create [auth_basic] folder
PS C:\Users\Administrator> New-Item -ItemType Directory -Path "IIS:\Sites\RX-7.srv.world\auth_basic"
Directory: WebAdministration::\\RX-7\Sites\RX-7.srv.world
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 9/9/2019 7:21 PM auth_basic
# disable anonymous authentication for target folder
PS C:\Users\Administrator> Set-WebConfigurationProperty -Filter '/system.webServer/security/authentication/anonymousAuthentication' -Location "RX-7.srv.world/auth_basic" -Name enabled -Value False
# enable basic authentication for target folder
PS C:\Users\Administrator> Set-WebConfigurationProperty -Filter '/system.webServer/security/authentication/basicAuthentication' -Location "RX-7.srv.world/auth_basic" -Name enabled -Value True
# restart target Web site
PS C:\Users\Administrator> Restart-WebItem -PSPath 'IIS:\Sites\RX-7.srv.world'
# create a test page
PS C:\Users\Administrator> Write-Output "Basic Authentication Test Page" | Out-File C:\inetpub\newsite\auth_basic\index.html -Encoding Default
# verify accesses ⇒ [-u (username)]
PS C:\Users\Administrator> curl.exe -u Serverworld https://rx-7.srv.world/auth_basic/
Enter host password for user 'Serverworld': # user password
Basic Authentication Test Page
Cấu hình trên GUI
Mở Server Manager và chọn Add roles and features, sau đó đánh dấu vào ô Basic Authentication và cài đặt nó.
![](https://cloudviet.com.vn/wp-content/uploads/2022/11/Basic_Authentication.png)
Sau khi cài đặt xong, restart lại IIS
![](https://cloudviet.com.vn/wp-content/uploads/2022/11/Basic_Authentication_1.png)
Tạo một thư mục mà bạn muốn đặt Basic Authentication.
Trong ví dụ này, hãy tạo một thư mục [auth_basic] cho nó. Đồng thời thêm quyền truy cập NTFS cho người dùng hoặc nhóm bạn muốn cho phép truy cập vào thư mục.
Mở [Server Manager] chọn [Tools] – [Internet Information Services (IIS) Manager], sau đó Chọn thư mục bạn muốn đặt Basic Authentication ở ngăn bên trái, rồi Mở để nhấp vào [Authentication] ở ngăn giữa.
![](https://cloudviet.com.vn/wp-content/uploads/2022/11/Basic_Authentication_2.png)
Tiếp theo, tắt [Anonymous Authentication] và bật [Basic Authentication]
![](https://cloudviet.com.vn/wp-content/uploads/2022/11/Basic_Authentication_3.png)
Tạo một trang kiểm tra trong thư mục bạn đã đặt [Basic Authentication] và xác minh quyền truy cập. Xác thực với người dùng mà bạn đã đặt để cho phép truy cập.
![](https://cloudviet.com.vn/wp-content/uploads/2022/11/Basic_Authentication_4.png)
Không sao nếu xác thực thành công và trang kiểm tra hiển thị bình thường.
![](https://cloudviet.com.vn/wp-content/uploads/2022/11/Basic_Authentication_5.png)