c#


ASP.NET Web API Authentication with Custom ApplicationUser With an extra Object


I've added an object 'Person' to my applicationuser class. This works fine until I want to do get and return something from this object.
My custom ApplicationUser class:
public class ApplicationUser : IdentityUser
{
public Person Person { get; set; }
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager, string authenticationType)
{
// Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
var userIdentity = await manager.CreateIdentityAsync(this, authenticationType);
//Add claims
// Add custom user claims here
return userIdentity;
}
}
And my Get:
public IHttpActionResult Get()
{
var models = _mailViewModelFactory.CreateListOfCompanyMails(_internshipCompanyRepository.GetAllCompanies());
return Ok(models);
}
And my mailViewFactory CreateListOfCompanyMails method:
public IEnumerable<MailWithNameViewModel> CreateListOfCompanyMails(IEnumerable<InternshipCompany> internshipCompanies)
{
var mailWithNameList = from internshipCompany in internshipCompanies
select new MailWithNameViewModel()
{
MailAddress = internshipCompany.Email, /* Only showing this works */
Name = internshipCompany.Person.Firstname /* When added this I get an error */
};
return mailWithNameList;
}
And my error:
{"Message":"An error has occurred.","ExceptionMessage":"The 'ObjectContent`1' type failed to serialize the response body for content type 'application/json; charset=utf-8'.","ExceptionType":"System.InvalidOperationException","StackTrace":null,"InnerException":{"Message":"An error has occurred.","ExceptionMessage":"De objectverwijzing is niet op een exemplaar van een object ingesteld.","ExceptionType":"System.NullReferenceException","StackTrace":" bij InternCOWebApi.ModelFactory.MailViewModelFactory.<>c.<CreateListOfCompanyMails>b__0_0(InternshipCompany internshipCompany) in D:\\Documenten\\GitHub\\AppDev11_2017\\Applicatie Backend\\InternCOWebApi\\InternCOWebApi\\Models\\ModelFactory\\MailViewModelFactory.cs:regel 19\r\n bij System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext()\r\n bij Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeList(JsonWriter writer, IEnumerable values, JsonArrayContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)\r\n bij Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty)\r\n bij Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value, Type objectType)\r\n bij Newtonsoft.Json.JsonSerializer.SerializeInternal(JsonWriter jsonWriter, Object value, Type objectType)\r\n bij System.Net.Http.Formatting.BaseJsonMediaTypeFormatter.WriteToStream(Type type, Object value, Stream writeStream, Encoding effectiveEncoding)\r\n bij System.Net.Http.Formatting.JsonMediaTypeFormatter.WriteToStream(Type type, Object value, Stream writeStream, Encoding effectiveEncoding)\r\n bij System.Net.Http.Formatting.BaseJsonMediaTypeFormatter.WriteToStream(Type type, Object value, Stream writeStream, HttpContent content)\r\n bij System.Net.Http.Formatting.BaseJsonMediaTypeFormatter.WriteToStreamAsync(Type type, Object value, Stream writeStream, HttpContent content, TransportContext transportContext, CancellationToken cancellationToken)\r\n--- Einde van stacktracering vanaf vorige locatie waar uitzondering is opgetreden ---\r\n bij System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n bij System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n bij System.Web.Http.WebHost.HttpControllerHandler.<WriteBufferedResponseContentAsync>d__1b.MoveNext()"}}
If I'm understanding the situation right, then this happens because I do not use any Claims? I saw how you could do this with a string but I couldn't find it how you could do it with an Object. Your help is much appreciated.

Related Links

How to add ComboBox column in XCeed DataGridControl (WPF)
Stream DateTime value,return Epoch value instead of “human” value
Finding a PowerPoint shape using Alternative text without looping through all shapes in C#
ASP.Net Page not loading when locale is en
Use c# variable in Jquery
How to use BeginInvoke in VB.NET
Looping through values in a string variable taken from a BizTalk message
Using RegEx to split strings after specific character
How to proper validate SSL certificate with X509Certificate2 on Mono and multiple platforms
How to persist and authenticate users from an MVC application to a Web API
Paged AD Query Sometimes Fails
How to pass multiple params to WebAPI?
HttpPut: “Index was out of range. Must be non-negative and less than the size of the collection” exception, but my data is still updated
Imgproc.FindContours return empty contours
linq SQL statements for joining two id with single list
C# Create a .NET object for JSON serialization and deserialization [duplicate]

Categories

HOME
drupal
max
model-view-controller
azure-active-directory
postgresql-9.3
abc
reference
x86-64
xss
kohana
zabbix
jquery-select2
markdown
browserstack
wavefront
jpql
chef-recipe
infopath
jsfiddle
game-engine
taxonomy
ampscript
computation-theory
datazen-server
combinations
angular2-pipe
struts
sasl
android-cursorloader
cloudformation
large-files
typeclass
arp
visual-prolog
eclipse-jdt
availability
jsonapi-resources
webclient
gitosis
kepserverex
matrix-multiplication
var
observer-pattern
google-chrome-console
flume-ng
pexpect
remap
google-cloud-shell
dna-sequence
bioperl
business-catalyst
copy-constructor
firebase-job-dispatcher
firebase-polymer
mongodb-3.3
magick.net
falcon
android-xmlpullparser
django-taggit
supervised-learning
jde
sqlxml
bbedit
calc
methodology
event-tracking
polarion
clearquest
targetprocess
stderr
httpmodule
chunks
caption
lwuit
im4java
dotcmis
time-frequency
drawable
rails-migrations
telerik-appbuilder
azure-caching
nodeunit
ojb
stringstream
google-checkout
http-compression
magicsuggest
pageload
blotter
netzke
databus
pinchzoom
ruby-1.9
flexbuilder
openwrap
youtube.net-api
designated-initializer
meego-harmattan
hs-err
iphone-maps
pitch-shifting
appointment
zend-acl
cstring
paperless

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App