相关疑难解决方法(0)

ASP.NET Core 2.0身份验证中间件

随着Core 1.1遵循@ blowdart的建议并实施了自定义中间件:

/sf/answers/2202565921/

它的工作方式如下:

  1. 中间件运行了.从请求标头中选取一个令牌.
  2. 验证了令牌,如果有效,则构建一个包含多个声明的身份(ClaimsIdentity),然后通过HttpContext.User.AddIdentity()添加;
  3. 在使用services.AddAuthorization的ConfigureServices中,我添加了一个策略来要求中间件提供的声明.
  4. 在控制器/操作中,我将使用[授权(角色="中间件添加的某些角色")]

这有点适用于2.0,除了如果令牌无效(上面的步骤2)并且从未添加声明我得到"没有指定authenticationScheme,并且没有找到DefaultChallengeScheme."

所以现在我正在读取2.0中的auth更改:

https://docs.microsoft.com/en-us/aspnet/core/migration/1x-to-2x/identity-2x

在ASP.NET Core 2.0中我做同样的事情的正确途径是什么?我没有看到做真正的自定义身份验证的示例.

c# authentication asp.net-core asp.net-core-2.0

84
推荐指数
2
解决办法
5万
查看次数

使用C#根据LDAP对用户进行身份验证

我正在使用DirectorySearcher在LDAP服务器中搜索用户条目.

DirectoryEntry de = new DirectoryEntry();
de.Path = "LDAP://myserver/OU=People,O=mycompany";
de.AuthenticationType = AuthenticationTypes.None;

DirectorySearcher deSearch = new DirectorySearcher();

deSearch.SearchRoot = de;
deSearch.Filter = "(uid=" + model.UserName + ")";

SearchResult result = deSearch.FindOne();
Run Code Online (Sandbox Code Playgroud)

我能够在结果变量中得到预期的输出.
但是,如果我尝试通过在目录条目中提供密码来验证同一用户,我总是会收到以下错误.

"用户名或密码不正确."

DirectoryEntry entry = new DirectoryEntry("LDAP://myserver/OU=People,O=mycompany", username, password);
DirectorySearcher search = new DirectorySearcher(
    entry,
    "(uid=" + username + ")",
    new string[] { "uid" }
);

search.SearchScope = System.DirectoryServices.SearchScope.Subtree;
SearchResult found = search.FindOne();   ->>>>>this is where I get wrong credential error.
Run Code Online (Sandbox Code Playgroud)

用户名和密码适用于我要验证的用户.

任何人都可以告诉我这里我做错了什么或如何调试这个.

c# authentication ldap

21
推荐指数
1
解决办法
7万
查看次数

如何在 ASP.NET Core 中使用 Active Directory 身份验证?

我正在使用 ASP.NET Core 2.1 React SPA Microsoft 模板。

我想使用 Active Directory 进行用户身份验证。我们的服务器使用 Active Directory 域标识在公司网络上运行。

我该怎么做?

active-directory asp.net-core-2.1

13
推荐指数
1
解决办法
3万
查看次数

Linux 下带 dotnet 核心的 LDAP

我正在开发一个基于 .net core (2.2.103) 的应用程序,它必须连接到 LDAP 服务器。在运行 Windows 的开发机器上,我使用了System.DirectoryServices命名空间。但是,该应用程序必须在 Linux (Ubuntu) 上运行,并且我得到了一个PlatformNotSupportedException,所以我添加了一个引用 <PackageReference Include="Novell.Directory.Ldap" Version="2.2.1" />并使用了它。

不幸的是,PlatformNotSupportedException当连接被处理时,这会引发另一个(但由于线程中止):

Unhandled Exception: System.PlatformNotSupportedException: Thread abort is not supported on this platform.
   at System.Threading.Thread.Abort()
   at Novell.Directory.Ldap.Connection.Dispose(Boolean disposing, String reason, Int32 semaphoreId, InterThreadException notifyUser)
   at Novell.Directory.Ldap.Connection.destroyClone(Boolean apiCall)
   at Novell.Directory.Ldap.LdapConnection.Finalize()
Run Code Online (Sandbox Code Playgroud)

Linux 上的 dotnet core 是否有可靠的 LDAP 实现?

linux ldap .net-core

4
推荐指数
2
解决办法
8874
查看次数

如何检查用户是否是组成员

我的目标是检查用户是否是特定活动目录组的成员。

.net mvc中,我在我的服务中使用了这段代码

HttpContext.Current.Request.LogonUserIdentity.Groups
                    .Any(x => x.Translate(typeof(NTAccount)).Value == "some role"
Run Code Online (Sandbox Code Playgroud)

效果很好。在.net core mvc 2.1.2中,我传递IHttpContextAccessor到服务构造函数并尝试使用以下内容

_httpAccessor.HttpContext.User.Identity.LogonUserIdentity.Groups
Run Code Online (Sandbox Code Playgroud)

但有一个问题,因为Identity不包含LogonUserIdentity. 我尝试找到任何解决方案,但没有成功,如何获取用户组列表或检查用户是否是特定组的成员?

asp.net-mvc asp.net-core

3
推荐指数
1
解决办法
9594
查看次数