httpContext 用户身份

httpContext User Identity

我想根据用户身份限制用户对我网站的访问,我使用了以下代码,它在 Visual Studio 中工作正常,但是当我发布到 IIS 时发送 userIdentity= NULL 到数据库。

Dim httpContext__1 As HttpContext = HttpContext.Current
Dim winIdentity As System.Security.Principal.WindowsIdentity = DirectCast(httpContext__1.User.Identity, WindowsIdentity)
Dim userIdentity As String = winIdentity.Name

hasAccess = GetUserFromDB(userIdentity)
If hasAccess Then
    ' restrictions on 
Else
End If

我们需要确保 Windows 身份验证已启用并且匿名身份验证已禁用。Please See This Link