我有一个 ASP .NET MVC5 应用程序not使用 Windows 身份验证。
一切都工作正常,直到我尝试在正在开发的域之外运行应用程序并且(无论出于何种原因)得到:
The trust relationship between this workstation and the primary domain failed.
当我想做的时候User.IsInRole("Admin")
.
我正在使用自定义Identity
, Role
, IdentityStore
, RoleStore
等来自 .NET 的Identity http://www.asp.net/identity我可以看到正在从(MongoDB)数据库正确检索用户和角色数据。
关于这个问题有很多问题,但它们来自那些want to使用 Windows 身份验证。以及 MVC 应用程序中的模拟:
使用 Windows 身份验证,调用 IsInRole 时,主域和受信任域之间的信任关系失败 https://stackoverflow.com/questions/2625509/with-windows-authentication-the-trust-relationship-between-the-primary-domain-a
如何配置 Windows 身份验证/模拟 + IIS 7 + MVC https://stackoverflow.com/questions/7665710/how-to-configure-windows-authentication-impersonation-iis-7-mvc
主域与受信任域之间的信任关系失败 https://serverfault.com/questions/497586/the-trust-relationship-between-the-primary-domain-and-the-trusted-domain-failed
My.User.IsInRole("角色名称") 在 Windows 7 上引发信任关系错误 http://social.msdn.microsoft.com/Forums/en-US/75f7964b-c90f-487d-ae0c-82678dbe0c6e/myuserisinrolerole-name-throws-a-trust-relationship-error-on-windows-7?forum=vblanguage
那么为什么我会得到这个SystemException
如果我没有使用 Active Directory 并且(据我所知)没有执行任何可能依赖于 PC 域的操作?我是否缺少一些配置(在我的Web.config
或 IIS Express)?
EDIT:
好吧,所以缩小范围一点......
My User.IsInRole("Admin")
线在一个里面if()
我的声明_Layout.cshtml
查看(即根据角色了解导航栏中显示的内容)。
我现在知道,只有在没有用户经过身份验证并且我不在用于开发的域中时,我才会收到上述错误。如果我在该行上放置一个断点,我可以看到User
对象是一个System.Security.Principal.WindowsIdentity
及其底层Identity
is System.Security.Principal.WindowsIdentity
.
另一方面,如果用户已通过身份验证,则User
对象和 tsIdentity
are System.Security.Claims.ClaimsPrincipal
and System.Security.Claims.ClaimsIdentity
.
为什么它完全使用 Windows 身份(未经身份验证时)以及如何禁用它?