【问题标题】:httpContext User IdentityhttpContext 用户身份
【发布时间】:2015-08-19 12:59:03
【问题描述】:

我想根据用户身份限制用户对我网站的访问,我使用了以下代码,它在 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

【问题讨论】:

  • 您似乎将 Visual Basic 代码与 Visual C# 代码混合在一起。你在用一种新的语言写作吗?也许是 Visual BasicC#? :)
  • 嗨 #Visual Vincent 我不是在制作新语言,只是写了伪代码,但看起来像 C#。
  • 因为你有实际的代码 - 发布
  • 现在我已经用 VB 代码更新了 :)
  • 我知道你不是在创造一种新语言,我只是在开玩笑,因为你似乎混合了这些语言。 :)

标签: asp.net vb.net iis httpcontext


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-01-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多