从移动设备注册用户到.net核心

时间:2018-06-02 16:00:48

标签: asp.net-core

我尝试在.net核心中使用 xamarin 注册用户,启用身份和会员系统,它返回true但没有用户在数据库中注册。 我也可以查看 MVC 网站,一切都很好

我的代码是

using (var client = new HttpClient())
                {
                    var model = new RegisterBindingModel
                    {
                        Email = email,
                        Password = password,
                        ConfirmPassword = confirmPassword
                    };

                    var json = JsonConvert.SerializeObject(model);

                    HttpContent httpContent = new StringContent(json);

                    httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");

                    var response = await client.PostAsync(
                        Constants.SignalrEndpointAddress + "Account/Register", httpContent);

                    if (response.IsSuccessStatusCode)
                    {
                        return true;
                    }
                }

1 个答案:

答案 0 :(得分:0)

问题出现在 StringContent 中,我的代码最终达到了这个目的:

using (var client = new HttpClient())
                {
                var model = new Dictionary<string, string>
                    {
                    {"Email", email },
                    {"Password", password},
                    {"ConfirmPassword", confirmPassword},
                    };

                var httpContent = new FormUrlEncodedContent(model);
                    var response = await client.PostAsync(
                        Constants.EndpointAddress + "Account/Register", httpContent);

                    if (response.IsSuccessStatusCode)
                    {
                        return true;
                    }
                }

感谢