Unable to cast object of type 'System.Security.Claims.ClaimsIdentity' to type...
up vote
1
down vote
favorite
I have 3 applications that I am trying to test running them locally.
On first one I am running integration test that is calling second ('middle') application that is supposed to create a quote on it's local system and then call third system that is company 'global' system responsible for user management.
It fails while casting System.Security.Claims.ClaimsIdentity to System.Security.Principal.WindowsIdentity
in
protected ApplicationAuthorisationService()
{
CurrentIdentity = (WindowsIdentity)Thread.CurrentPrincipal.Identity;
}
I have little knowledge of 'global system responsible for user management' since it is being handled by other department still I need to investigate why tests on my local machine are failing.
'middle' application is constructing url and simply calling global one by GET
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;
}
}
fragment that makes actual call.
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>();
}
What could be the cause of this?
c# .net security casting
add a comment |
up vote
1
down vote
favorite
I have 3 applications that I am trying to test running them locally.
On first one I am running integration test that is calling second ('middle') application that is supposed to create a quote on it's local system and then call third system that is company 'global' system responsible for user management.
It fails while casting System.Security.Claims.ClaimsIdentity to System.Security.Principal.WindowsIdentity
in
protected ApplicationAuthorisationService()
{
CurrentIdentity = (WindowsIdentity)Thread.CurrentPrincipal.Identity;
}
I have little knowledge of 'global system responsible for user management' since it is being handled by other department still I need to investigate why tests on my local machine are failing.
'middle' application is constructing url and simply calling global one by GET
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;
}
}
fragment that makes actual call.
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>();
}
What could be the cause of this?
c# .net security casting
"so this exception makes little sense" - If the inheritance was the other way around, the exception wouldn't make sense. Apples (WindowsIdentity) are a type of Fruit (ClaimsIdentity). That doesn't mean that you can take any random piece of Fruit and magically turn it into an Apple.
– Damien_The_Unbeliever
Jun 24 '15 at 10:11
@Damien_The_Unbeliever I just had one of those moments where I question myself am I stupid or blind. Thanks.
– Matas Vaitkevicius
Jun 24 '15 at 10:14
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I have 3 applications that I am trying to test running them locally.
On first one I am running integration test that is calling second ('middle') application that is supposed to create a quote on it's local system and then call third system that is company 'global' system responsible for user management.
It fails while casting System.Security.Claims.ClaimsIdentity to System.Security.Principal.WindowsIdentity
in
protected ApplicationAuthorisationService()
{
CurrentIdentity = (WindowsIdentity)Thread.CurrentPrincipal.Identity;
}
I have little knowledge of 'global system responsible for user management' since it is being handled by other department still I need to investigate why tests on my local machine are failing.
'middle' application is constructing url and simply calling global one by GET
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;
}
}
fragment that makes actual call.
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>();
}
What could be the cause of this?
c# .net security casting
I have 3 applications that I am trying to test running them locally.
On first one I am running integration test that is calling second ('middle') application that is supposed to create a quote on it's local system and then call third system that is company 'global' system responsible for user management.
It fails while casting System.Security.Claims.ClaimsIdentity to System.Security.Principal.WindowsIdentity
in
protected ApplicationAuthorisationService()
{
CurrentIdentity = (WindowsIdentity)Thread.CurrentPrincipal.Identity;
}
I have little knowledge of 'global system responsible for user management' since it is being handled by other department still I need to investigate why tests on my local machine are failing.
'middle' application is constructing url and simply calling global one by GET
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;
}
}
fragment that makes actual call.
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>();
}
What could be the cause of this?
c# .net security casting
c# .net security casting
edited Jun 24 '15 at 13:14
asked Jun 24 '15 at 9:58
Matas Vaitkevicius
32.3k15161171
32.3k15161171
"so this exception makes little sense" - If the inheritance was the other way around, the exception wouldn't make sense. Apples (WindowsIdentity) are a type of Fruit (ClaimsIdentity). That doesn't mean that you can take any random piece of Fruit and magically turn it into an Apple.
– Damien_The_Unbeliever
Jun 24 '15 at 10:11
@Damien_The_Unbeliever I just had one of those moments where I question myself am I stupid or blind. Thanks.
– Matas Vaitkevicius
Jun 24 '15 at 10:14
add a comment |
"so this exception makes little sense" - If the inheritance was the other way around, the exception wouldn't make sense. Apples (WindowsIdentity) are a type of Fruit (ClaimsIdentity). That doesn't mean that you can take any random piece of Fruit and magically turn it into an Apple.
– Damien_The_Unbeliever
Jun 24 '15 at 10:11
@Damien_The_Unbeliever I just had one of those moments where I question myself am I stupid or blind. Thanks.
– Matas Vaitkevicius
Jun 24 '15 at 10:14
"so this exception makes little sense" - If the inheritance was the other way around, the exception wouldn't make sense. Apples (WindowsIdentity) are a type of Fruit (ClaimsIdentity). That doesn't mean that you can take any random piece of Fruit and magically turn it into an Apple.
– Damien_The_Unbeliever
Jun 24 '15 at 10:11
"so this exception makes little sense" - If the inheritance was the other way around, the exception wouldn't make sense. Apples (WindowsIdentity) are a type of Fruit (ClaimsIdentity). That doesn't mean that you can take any random piece of Fruit and magically turn it into an Apple.
– Damien_The_Unbeliever
Jun 24 '15 at 10:11
@Damien_The_Unbeliever I just had one of those moments where I question myself am I stupid or blind. Thanks.
– Matas Vaitkevicius
Jun 24 '15 at 10:14
@Damien_The_Unbeliever I just had one of those moments where I question myself am I stupid or blind. Thanks.
– Matas Vaitkevicius
Jun 24 '15 at 10:14
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
For those wondering.
Issue was that version of project was set to .NET 4.0 while this inheritance get's implemented on .NET 4.5
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f31023476%2funable-to-cast-object-of-type-system-security-claims-claimsidentity-to-type-s%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
For those wondering.
Issue was that version of project was set to .NET 4.0 while this inheritance get's implemented on .NET 4.5
add a comment |
up vote
1
down vote
accepted
For those wondering.
Issue was that version of project was set to .NET 4.0 while this inheritance get's implemented on .NET 4.5
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
For those wondering.
Issue was that version of project was set to .NET 4.0 while this inheritance get's implemented on .NET 4.5
For those wondering.
Issue was that version of project was set to .NET 4.0 while this inheritance get's implemented on .NET 4.5
answered Jun 24 '15 at 13:03
Matas Vaitkevicius
32.3k15161171
32.3k15161171
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f31023476%2funable-to-cast-object-of-type-system-security-claims-claimsidentity-to-type-s%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
"so this exception makes little sense" - If the inheritance was the other way around, the exception wouldn't make sense. Apples (WindowsIdentity) are a type of Fruit (ClaimsIdentity). That doesn't mean that you can take any random piece of Fruit and magically turn it into an Apple.
– Damien_The_Unbeliever
Jun 24 '15 at 10:11
@Damien_The_Unbeliever I just had one of those moments where I question myself am I stupid or blind. Thanks.
– Matas Vaitkevicius
Jun 24 '15 at 10:14