Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无法强制转换类型为';系统、安全、索赔、索赔实体';输入';System.Security.Principal.WindowsIdentity';_C#_.net_Security_Casting - Fatal编程技术网

C# 无法强制转换类型为';系统、安全、索赔、索赔实体';输入';System.Security.Principal.WindowsIdentity';

C# 无法强制转换类型为';系统、安全、索赔、索赔实体';输入';System.Security.Principal.WindowsIdentity';,c#,.net,security,casting,C#,.net,Security,Casting,我有3个应用程序,我正在尝试在本地运行它们 在第一个系统中,我运行集成测试,调用第二个(“中间”)应用程序,该应用程序应该在其本地系统上创建报价,然后调用第三个系统,即负责用户管理的公司“全局”系统 将System.Security.Claims.ClaimsIdentity强制转换为System.Security.Principal.WindowsIdentity 在 我对“负责用户管理的全球系统”知之甚少,因为它是由其他部门处理的,但我仍需要调查本地机器上的测试失败的原因 “中间”应用程序正

我有3个应用程序,我正在尝试在本地运行它们

在第一个系统中,我运行集成测试,调用第二个(“中间”)应用程序,该应用程序应该在其本地系统上创建报价,然后调用第三个系统,即负责用户管理的公司“全局”系统

System.Security.Claims.ClaimsIdentity
强制转换为
System.Security.Principal.WindowsIdentity

我对“负责用户管理的全球系统”知之甚少,因为它是由其他部门处理的,但我仍需要调查本地机器上的测试失败的原因

“中间”应用程序正在构造url并通过GET简单地调用全局url

private HttpClient GetHttpClient()
{
    try
    {
        var client = new HttpClient
        {
            BaseAddress = this.BaseUri,
        };

        client.DefaultRequestHeaders.Accept.Clear();
        client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
        return client;
    }
    catch (Exception ex)
    {
        ILogHelper.LogException(ex, Log, LoggerLevel.Error);
        throw;
    }
}
进行实际调用的片段

using (var client = this.GetHttpClient())
{
    client.SetBearerToken(this._token.AccessToken);
    var uri = new Uri(client.BaseAddress, string.Format("api/crmcustomer/?FirstName={0}&Surname={1}&DateOfBirth={2}&PostCode={3}&GetLatestWhenThereAreMultipleResults={4}",
        parameter.FirstName,
        parameter.Surname,
        parameter.DateOfBirth.HasValue ? parameter.DateOfBirth.Value.ToString("yyyy-MM-dd") : string.Empty,
        parameter.PostCode,
        parameter.GetLatestWhenThereAreMultipleResults));

    this.Log.Info("URI: " + uri);

    this.Log.Debug("parameter.FirstName: " + parameter.FirstName);
    this.Log.Debug("parameter.Surname: " + parameter.Surname);
    if (parameter.DateOfBirth != null)
        this.Log.Debug("parameter.DateOfBirth: " + parameter.DateOfBirth.Value.ToString("yyyy-MM-dd"));
    this.Log.Debug("parameter.PostCode: " + parameter.PostCode);
    this.Log.Debug("parameter.GetLatestWhenThereAreMultipleResults: " + parameter.GetLatestWhenThereAreMultipleResults);
    var response = await client.GetAsync(uri).ConfigureAwait(false);
    response.EnsureSuccessStatusCode();
    return await response.Content.ReadAsAsync<CtiResponse>();
}
使用(var client=this.GetHttpClient())
{
client.SetBearerToken(this.\u token.AccessToken);
var uri=new uri(client.BaseAddress,string.Format(“api/crmcustomer/?FirstName={0}&姓氏={1}&出生日期={2}&邮政编码={3}&GetLatestWhenthereMultipleResults={4}”),
parameter.FirstName,
参数。姓氏,
parameter.DateOfBirth.HasValue?parameter.DateOfBirth.Value.ToString(“yyyy-MM-dd”):string.Empty,
参数。邮政编码,
参数.GetLatestWhenThereAreMultipleResults));
this.Log.Info(“URI:+URI”);
this.Log.Debug(“parameter.FirstName:+parameter.FirstName”);
this.Log.Debug(“parameter.姓氏:”+parameter.姓氏);
if(parameter.DateOfBirth!=null)
this.Log.Debug(“parameter.DateOfBirth:”+parameter.DateOfBirth.Value.ToString(“yyyy-MM-dd”);
this.Log.Debug(“parameter.PostCode:+parameter.PostCode”);
this.Log.Debug(“parameter.getlatestWhenthereMultipleResults:”+parameter.getlatestWhenthereMultipleResults);
var response=await client.GetAsync(uri).ConfigureAwait(false);
response.EnsureSuccessStatusCode();
return wait response.Content.ReadAsAsync();
}
这可能是什么原因?对于那些想知道的人来说


问题是project的版本就是这个继承

“所以这个异常没有什么意义”——如果继承是另一种方式,那么这个异常就没有意义。苹果(WindowsIdentity)是一种水果(ClaimsIdentity)。这并不意味着你可以随便拿一块水果,然后神奇地把它变成一个苹果。@Damien_,不信者,我刚才有一次问自己,我是愚蠢还是瞎了。谢谢
using (var client = this.GetHttpClient())
{
    client.SetBearerToken(this._token.AccessToken);
    var uri = new Uri(client.BaseAddress, string.Format("api/crmcustomer/?FirstName={0}&Surname={1}&DateOfBirth={2}&PostCode={3}&GetLatestWhenThereAreMultipleResults={4}",
        parameter.FirstName,
        parameter.Surname,
        parameter.DateOfBirth.HasValue ? parameter.DateOfBirth.Value.ToString("yyyy-MM-dd") : string.Empty,
        parameter.PostCode,
        parameter.GetLatestWhenThereAreMultipleResults));

    this.Log.Info("URI: " + uri);

    this.Log.Debug("parameter.FirstName: " + parameter.FirstName);
    this.Log.Debug("parameter.Surname: " + parameter.Surname);
    if (parameter.DateOfBirth != null)
        this.Log.Debug("parameter.DateOfBirth: " + parameter.DateOfBirth.Value.ToString("yyyy-MM-dd"));
    this.Log.Debug("parameter.PostCode: " + parameter.PostCode);
    this.Log.Debug("parameter.GetLatestWhenThereAreMultipleResults: " + parameter.GetLatestWhenThereAreMultipleResults);
    var response = await client.GetAsync(uri).ConfigureAwait(false);
    response.EnsureSuccessStatusCode();
    return await response.Content.ReadAsAsync<CtiResponse>();
}