相关疑难解决方法(0)

C#"使用"语法

use会捕获异常还是抛出异常?即

using (StreamReader rdr = File.OpenText("file.txt"))
{
 //do stuff
}
Run Code Online (Sandbox Code Playgroud)

如果streamreader抛出异常是通过使用或抛出来捕获的,那么调用函数可以处理它吗?

c# using exception using-statement

46
推荐指数
4
解决办法
3万
查看次数

System.DirectoryServices.AccountManagement.UserPrincipal.FindByIdentity的奇怪问题

我们正在编写一个允许用户通过Intranet上的Web应用程序更改其帐户密码的系统.

起初,一切似乎都在顺利进行.在开发期间,我们的测试帐户的密码可以毫无问题地更改.

然而,当我们制作系统时,我们开始遇到问题.以下是症状:

  1. 一开始,一切都很好.用户可以更改其密码.
  2. 在某些时候,UserPrincipal.FindByIdentity中出现以下错误:"System.Runtime.InteropServices.COMException:身份验证机制未知."
  3. 从那时起,尝试通过Web应用程序更改密码会导致错误:"System.Runtime.InteropServices.COMException:服务器无法运行."
  4. 如果我手动回收应用程序池,一切似乎都会自行解决,直到更多错误开始发生...即,该过程在第1阶段重新开始.

这是相关的代码片段:


    private static PrincipalContext CreateManagementContext() {
        return new PrincipalContext(
            ContextType.Domain, 
            ActiveDirectoryDomain, 
            ActiveDirectoryManagementAccountName,
            ActiveDirectoryManagementAccountPassword);
    }


    private static void ChangeActiveDirectoryPasword(string username, string password) {
        if (username == null) throw new ArgumentNullException("username");
        if (password == null) throw new ArgumentNullException("password");

        using (var context = CreateManagementContext())
        using (var user = UserPrincipal.FindByIdentity(context, IdentityType.SamAccountName, username)) {
            user.SetPassword(password);
        }
    }
Run Code Online (Sandbox Code Playgroud)

关于为什么会发生这种情况的任何线索?谷歌搜索没有提供任何真正有用的信息,MSDN上的文档也没有.

directoryservices memory-leaks ldap active-directory account-management

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