【问题标题】:PiranhaCMS - Get current Windows UserPiranhaCMS - 获取当前 Windows 用户
【发布时间】:2023-03-31 19:58:01
【问题描述】:

在全新的 ASP.Net Core 应用程序中,您可以选择“Windows 身份验证”,当您启动应用程序时,您会直接拥有 Windows 用户,并且可以在控制器中使用 User.Identity。

我想在 PiranhaCMS MVC V10.0.0 应用程序中获取 Windows 用户(如果可能,通过询问用户凭据,否则自动)并将其存储在 Piranha 用户/身份表中。

我尝试将 windowsAuthentication 设置为 true(在 launchSettings.json 中)并将其添加到 Startup.cs 中:

services.AddAuthentication(NegotiateDefaults.AuthenticationScheme)
    .AddNegotiate();
services.AddAuthorization(options => {
    options.FallbackPolicy = options.DefaultPolicy;
});

但 User.Identity.Name 在控制器中仍然为空(直到我使用默认管理员用户登录管理器)。

如何通过询问其(Windows 或 AD)凭据来获取当前 Windows 用户?

【问题讨论】:

    标签: c# asp.net-core piranha-cms


    【解决方案1】:

    我已经弄清楚如何通过添加 IIS Express 设置并在 launchSettings.json 中启动相应的配置文件来获取当前用户。

    我不知道为什么它需要在 PiranhaCMS 中而不是在新的 ASP.NET Core 应用中启动 IIS(以获取用户)。

    {
      "iisSettings": {
        "windowsAuthentication": true,
        "anonymousAuthentication": false,
        "iisExpress": { // Here the section that was missing
          "applicationUrl": "http://localhost:64223/",
          "sslPort": 44393
        }
      },
      "profiles": {
        "PiranhaCMS - Home": {
          "commandName": "Project",
          "launchBrowser": true,
          "applicationUrl": "http://localhost:31005",
          "environmentVariables": {
            "ASPNETCORE_ENVIRONMENT": "Development"
          }
        },
        "IIS Express": { // Here the profile that needed to be added
          "commandName": "IISExpress",
          "launchBrowser": true,
          "environmentVariables": {
            "ASPNETCORE_ENVIRONMENT": "Development"
          }
        }
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2010-10-19
      • 1970-01-01
      • 1970-01-01
      • 2010-11-13
      • 2012-12-19
      • 2013-08-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多