Click here to Skip to main content
16,015,973 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Code goes like this:

public async Task<AppUser> CreateUser(AppUser user, RegisterUserDto dto)
        {
            try
            {
                var result = await _userManager.CreateAsync(user, dto.Password);
                if (result.Succeeded)
                {
                    await _userManager.AddToRoleAsync(user, "Member");
                    await _context.SaveChangesAsync();
                    return user;
                }
                return null;
                
            }
            catch (Exception ex)
            {
                _logger.LogError("Error at AuthRepository at CreateUser, ex:" + ex.StackTrace, false);
            }
            return null;
        }



[HttpPost]
  [Route("createuser")]
  public async Task<IActionResult> CreateUserAcc([FromBody] RegisterUserDto userDto)
  {
      try
      {
          var identity = _mapper.Map<AppUser>(userDto);
          var result= await _repository.CreateUser(identity, userDto);
          if (result!=null)
              return Ok(result);
          else
              return BadRequest("Account alredy exists.");
      }
      catch (Exception)
      {

      }
      return BadRequest();
  }



Summary:
I'm trying to create user via CreateUser method, passing to it RegisterUserDto, and then in the POST request response body to return created user object.
Action executes and user is created in DB, but Postman returns this: Image

What I have tried:

I've made sure that Postman's SSL certificate verification is turned OFF.
Posted
Updated 14-Dec-18 18:55pm
Comments
Bryian Tan 14-Dec-18 11:06am    
What in the RegisterUserDto class?
1suli0 14-Dec-18 11:20am    
public class RegisterUserDto
{
public string Email { get; set; }
public string Password { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
}
It looks like this.
Bryian Tan 14-Dec-18 13:56pm    
try return Ok(JObject.Parse(result));
F-ES Sitecore 14-Dec-18 11:09am    
Why would we know why postman can't connect to a service running on your machine? We can't access it to diagnose what is running and what isn't. I'll start with the basics though....is your web service actually running and listening on that port? It looks like you're using Visual Studio's built-in web server and that only runs when your project is running so much sure you've started it in debug mode first. If that's the issue then change it to use IIS on your local machine as debugging APIs etc is easier that way as IIS is always running.
1suli0 14-Dec-18 11:19am    
Well, I've asked the question in hope that someone encountered similar problem, or to get a piece of advice. Thanks nevertheless.

1 solution

Configuring this in serializer options solved the problem.
services.AddMvc(options=>....).AddJsonOptions(opt=> opt.SerializerSettings.ReferenceLoopHandling=Newtonsoft.Json.ReferenceLoopHandling.Ignore);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900