Below is my HttpPost method where i am trying to pass input as DTo's
[HttpPost("register")]
public async Task<ActionResult<AppUser>> Register(RegisterDto registerDto)
{
if (await UserExists(registerDto.Username)) return BadRequest("Username is taken");
using var hmac = new HMACSHA512();
var user = new AppUser
{
UserName = registerDto.Username.ToLower(),
//UserName = username,
PasswordHash = hmac.ComputeHash(Encoding.UTF8.GetBytes(registerDto.Password)),
//PasswordHash = hmac.ComputeHash(Encoding.UTF8.GetBytes(password)),
PasswordSalt = hmac.Key
};
_context.Users.Add(user);
await _context.SaveChangesAsync();
return user;
}
}
And here it is the Dto class which i have created and which i passed in tht HttpPost method
Register Dto Class:-
public class RegisterDto
{
public string Username { get; set; }
public string Password { get; set; }
}
When i m trying to test this method in postman , it is throwing error as 415 unsupported media type , check the image below. Postman error:-