我们有一个ASP.NET站点,部分依赖于登录凭证的表单身份验证,但是IPrincipal的实现是完全自定义的。IPrincipal的自定义实现抛出System.SystemException:信任关系
但是,特定服务器上运行的网站时(这有点半硬化,当涉及到安全),应用程序崩溃与下列消息话题调用IPrincipal.IsInRole()时:
System.SystemException :主域和受信域之间的信任关系失败。
这表示Web服务器和DC之间的通信错误,但由于我们的应用程序根本不使用Windows身份验证,所以我不明白为什么它需要与DC通信。
这是我实现:
[Serializable]
public class CustomPrincipal : IPrincipal
{
public CustomPrincipal(IUser userObj)
{
this.Identity = new CustomIdentity(userObj.Id, userObj.Username);
}
public bool IsInRole(string role)
{
if (role == null)
return false;
var roles = HttpContext.Current.Session["authentication-roles"] as string[];
if (roles == null)
return false;
return Array.IndexOf(roles, role) >= 0;
}
public IIdentity Identity { get; private set; }
public CustomIdentity FullIdentity
{
get { return (CustomIdentity) this.Identity; }
}
}
当本地调试它(如果它的工作原理),它是正确的实现,实际上是运行。用法如下:
public override void Render()
{
var items = this.manager.Items
.Where(i => EngineContext.CurrentUser.IsInRole(i.Role.InternalName));
在这里设置一个断点给了我EngineContext.CurrentUser实际上是CustomPrincipal的实现。
有没有人遇到过这个? ASP.NET如何仍然可能触发Interface方法上的任何LDAP查找?
我发现这个,http://support.microsoft.com/kb/976494但在我的环境中,网络服务器和DC都是2008 R2,所以这不适用。但是,我的事件日志中存在一些错误,表明存在与DC有关的一些通信问题,但由于我们不依赖于LDAP,因此这应该不成问题。
安全系统无法与服务器ldap/ddc.domain.com/xxxxxxxxxxxxx建立安全连接。没有认证协议可用。
服务器超出我的范围,这意味着我无法自己解决这个问题,但我确实有一个支持凭单,但出于安全原因可能有意为此设置(尽管看起来很愚蠢) 。
有没有人遇到过这个问题?
跟帖:堆栈跟踪显示这一点:
at System.Security.Principal.NTAccount.TranslateToSids(IdentityReferenceCollection sourceAccounts, Boolean& someFailed)
at System.Security.Principal.NTAccount.Translate(IdentityReferenceCollection sourceAccounts, Type targetType, Boolean forceSuccess)
at System.Security.Principal.WindowsPrincipal.IsInRole(String role)
at Company.Sites.Manager.ViewComponents.MenuComponent.<Render>b__0(INavigationItem i)
编辑:
我终于能够复制我的开发机器上的这个错误(我是从DC昨天撤销我的机器,但没直到今天再现它)
HttpContext.User实际上是一个WindowsPrincipal默认情况下,它似乎和我的代码中的错误是,我只在登录时用CustomPrincipal替换它。因此,未经认证的用户仍然可以获得WindowsPrincipal,如果您的AD存在信任问题,那么WindowsPrincipal将会失败。
我试图通过调用该上AppStart的
AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.NoPrincipal);
改变默认的主体但这似乎并没有踢我如何更改ASP.NET默认的主体?
尝试在生产计算机上记录'EngineContext.CurrentUser'的类型。它最有可能不包含您的自定义主体。 – 2010-08-03 09:53:48