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

^[0-9]+$ is allowing white spaces in my asp.net web application, any patterns to correct it?
C# ASP Local Active Directory Login with AD Group Roles (Visual Studio 2015)
Create thumbnail from asset - Azure Media Services
Is this proper usage of IReferenceResolver inside a JsonConverter?
How to map 2d clothe image on skeleton coordinates obtained using kinect? [closed]
Changing member variable of child entity changes it for all parent entities
How to store ID from database object, to a checkbox in code behind WPF
ClosedXml Range Error
Using regex on MVC routes for controller action to allow only calls that don't contain a given word
Winform form border issue in windows 10
How to round up result of dividing
I want to show selected part of image in another picture box. How to do that?
When trying to delete a row, I get a Login failure when trying to open connection
Reading contents of an Office Document on save
BizTalk WCF returns 413 when using client certificates authentication
c# compare byte arrays

Categories

HOME
pact
repository
abc
liquibase
pandoc
psexec
comments
markdown
webpack-dev-server
cracking
dcos
coding-style
desktop-application
comma
nsoperation
pylint
jquery-easyui
md2
autologin
ajaxcontroltoolkit
fibonacci
multipart
struts
ckeditor4.x
android-xml
formtastic
workflow-foundation
csproj
request-uri
textview
blockly
jql
language-detection
zimbra
javax
anypoint-studio
nscollectionview
socketcluster
glide-image-library
compiler-warnings
uitextview
amazon-rds-aurora
vertex
jcifs
playframework-2.3
aws-rds
fckeditor
nservicebus6
try-catch-finally
reloaddata
timex
acceleo
directinput
toggleclass
ldd
avi
transaction-isolation
razorengine
camellia
salesforce-service-cloud
methodology
encode
angular-promise
glog
waterline
teamwork
mri
attiny
chunks
nsq
javadb
selenium-grid2
mixradio
mdp
nop
dylan
playing-cards
xrandr
uikit-dynamics
latex-suite
qmainwindow
windows-scheduler
screensharing
states
certificate-revocation
django-admin-tools
stl-algorithm
peoplepicker
qvariant
response-time
netbeans7.0
datarelation
nyromodal
system-analysis
content-delivery-network
j++

Resources

Encrypt Message