I have a WebApi login function:
public HttpResponseMessage Login(MyUser user)
{
Repository r = new Repository();
user = r.Select<MyUser>(u => u.Login == user.Login && u.Password == user.Password).FirstOrDefault();
if (user == null)
{
// - No user found/wrong password, returning error
}
// - User found
MyIdentity m = new MyIdentity(user);
m.SignIn(); // - creates cookie, logins
return Request.CreateResponse<Response>(HttpStatusCode.OK, new Response(true, "User logged in.", user));
}
The Response
class is a generic response I use to deal with Ajax stuff and it accepts an object optionally:
public class Response
{
public bool Status { get; set; }
public string Message { get; set; }
public object Data { get; set; }
}
Whenever I call the function, I get the expected JSON for the Response and any object attached, if any, on Internet Explorer, Edge, Opera and Chrome, but Firefox throws an exception of:
System.Runtime.Serialization.SerializationException: Type 'Serialization.Dog' with data contract name 'Dog:http://schemas.datacontract.org/2004/07/Serialization' is not expected. Consider using a DataContractResolver or add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.
and I end up getting a error 500 as result.
Why is that and what's the proper way to deal with this to work with all browsers?