【问题标题】:HttpContext.User.Identity doesn't work in release modeHttpContext.User.Identity 在发布模式下不起作用
【发布时间】:2021-07-01 17:14:03
【问题描述】:

我想使用 HttpContext.User.Identity,它在 Debug 中完美运行,但是当我发布它时无法识别 Windows 用户。

这是launchsetting.json文件

{   "iisSettings": {
    "windowsAuthentication": true,
    "anonymousAuthentication": false,
    "iisExpress": {
      "applicationUrl": "http://localhost:53960/",
      "sslPort": 0
    }   },   "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "DataManager": {
      "commandName": "Project",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      },
      "applicationUrl": "http://localhost:53961/"
    }   } }

我目前使用的是 .net core 2.0

更新:这是我的appsettings.json 文件

{
  "ConnectionStrings": {
    "GlossaryConnection": "██████████████",
    "EmployeeConnection": "██████████████"
  },
  "Logging": {
    "IncludeScopes": false,
    "LogLevel": {
      "Default": "Warning"
    }
  }
}

【问题讨论】:

  • “ASPNETCORE_ENVIRONMENT”:“生产”? docs.microsoft.com/pl-pl/aspnet/core/fundamentals/…
  • 不,它不起作用
  • 您是否在发布模式下通过 Visual Studio 运行应用程序?因为,这并不是 lauchSettings.json 真正要支持的……另一方面,appSettings.json 是为了支持在 VS 之外运行应用程序。
  • 更新:添加 appsettings.json
  • 您在哪里部署应用程序? IIS?如果应用宿主在 IIS 上,请检查 IIS Authentication 配置(打开 IIS,选择网站,双击 Authentication,勾选authentication configuration),确保 Windows Authentication 为 Enabled,Anonymous Authentication 为 Disabled 状态。跨度>

标签: .net asp.net-core asp.net-identity


【解决方案1】:

感谢@Zhi Lv 我只需要检查 IIS 身份验证配置(打开 IIS,选择网站,双击身份验证,然后检查身份验证配置),确保启用 Windows 身份验证和禁用匿名身份验证状态

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-09-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-16
    • 2022-08-08
    • 2012-09-28
    • 2021-04-28
    相关资源
    最近更新 更多