动态CRM SDK在C#中连接与无效的密码 [英] Dynamics CRM SDK in C# connect with Invalid Password

查看:135
本文介绍了动态CRM SDK在C#中连接与无效的密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发用于检索Dynamics CRM Online中的数据的一个C#应用程序。为了验证动态CRM的用户名和密码我使用的WhoAmIRequest。直到下面的场景occures它工作正常。

I am developing one C# application which is used to retrieve data from Dynamics CRM Online. To validate the User Name and Password of Dynamics CRM I am using the WhoAmIRequest. It works fine until the below scenario occures.

1)有效的URL,用户名和密码连接Dynamics CRM中。

1)Connect the Dynamics CRM with Valid URL, User Name and Password.

2)配置组织服务对象。

2) Dispose the Organization Service Object.

3)有效的URL,用户名和密码无效重新连接动态CRM。

3) Reconnect the Dynamics CRM with Valid URL, User Name and Invalid Password.

在这种情况下也得到了WhoAmIRequest成功执行。但应该失败

In this scenario also the WhoAmIRequest got executed Successfully. But it should fail.

下面是我使用的代码:

private void button6_Click(object sender, EventArgs e)
    {
        CrmConnection connection;
        string url = "Url=https://mytest.crm.dynamics.com ;Username=mytest@mytest.onmicrosoft.com; Password=goodpassword;";
        connection = CrmConnection.Parse(url);
        OrganizationService orgService = new OrganizationService(connection);
        Guid userid = ((WhoAmIResponse)orgService.Execute(new WhoAmIRequest())).UserId;
        if (userid == null)
            MessageBox.Show("Login Failed");
        else
            MessageBox.Show("Login Success");
        orgService.Dispose();

        url = "Url=https://mytest.crm.dynamics.com ;Username=mytest@mytest.onmicrosoft.com; Password=badpassword;";
        connection = CrmConnection.Parse(url);
        orgService = new OrganizationService(connection);
        userid = ((WhoAmIResponse)orgService.Execute(new WhoAmIRequest())).UserId;
        if (userid == null)
            MessageBox.Show("Login Failed");
        else
            MessageBox.Show("Login Success");
        orgService.Dispose();

        url = "Url=https://mytest.crm.dynamics.com ;Username=mytest@mytest.onmicrosoft.com; Password=goodpassowrd;";
        connection = CrmConnection.Parse(url);
        orgService = new OrganizationService(connection);
        userid = ((WhoAmIResponse)orgService.Execute(new WhoAmIRequest())).UserId;
        if (userid == null)
            MessageBox.Show("Login Failed");
        else
            MessageBox.Show("Login Success");
        orgService.Dispose();
    }



以上代码的输出显示了3个消息框为

The output of above code shows 3 message box as

登录成功

登录成功

登录成功

但应为

登录成功

显示登录失败

登录成功

我也尝试了答案通过的 Nicknow 中的需要验证凭据CRM 的问题,但没有什么帮助。

I have also tried the answer suggest by Nicknow in the the Need to validate CRM credentials Question but nothing helps

任何帮助将不胜感激。

感谢和问候
卡特桑

Thanks and Regards Venkatesan

推荐答案

问题出在你的支票这里:

The problem is in your check here:

如果(用户ID == NULL)

用户ID是一个GUID,GUID是一个结构,一个结构是一值类型和值类型永远不会,以便检查始终返回false。

UserId is a Guid, Guid is a struct, a struct is a value type, and a value type will never be null, so that check always returns false.

在这里看到更多信息的Guid = NULL不应该由编译器允许

我会建议使用下面的检查,而不是:

I would suggest using the following check instead:

如果(用户ID == Guid.Empty)

这篇关于动态CRM SDK在C#中连接与无效的密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆