我的应用程序使用UserPrincipal
类来确定用户属于哪些组,然后使用该信息来确定用户是否经过身份验证才能使用我的应用程序。有一段时间一切都很好,但最近我开始遇到异常
Guid 应包含 32 位数字和 4 个破折号 (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)
打电话时UserPrincipal.FindByIdentity
。看起来调用成功并且异常得到了正确处理,但这让我担心将来身份验证会突然中断。我没有在任何地方显式创建 GUID,所以我不知道异常来自哪里。
最有可能的是,在尝试从无效 GUID 值初始化某种安全描述符的框架代码深处抛出异常。如果框架能够捕获它并在内部处理它,我就不会担心它。
跟踪框架代码,这里是一个可能发生这种情况的地方:
protected static bool IdentityClaimToFilter(string identity, string identityFormat, ref string filter, bool throwOnFail)
{
if (identity == null)
identity = "";
StringBuilder filter1 = new StringBuilder();
switch (identityFormat)
{
case "ms-guid":
Guid guid;
try
{
guid = new Guid(identity);
}
catch (FormatException ex)
{
if (throwOnFail)
throw new ArgumentException(ex.Message, (Exception) ex);
else
return false;
}
...
请注意,它tries创建一个新的Guid
,如果失败,则会抛出异常,但代码会吞掉它并仅返回 false
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)