内部服务器错误api/帐户/注册 [英] Internal Server Error api/account/register

查看:112
本文介绍了内部服务器错误api/帐户/注册的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在回发信息以在Web API 2中注册单个帐户时,我收到内部服务器错误.它发生在client.PostAsync上. api/account/register与创建Web API 2项目以使用单个帐户时创建的内容相同.

I am getting an internal server error when posting information back to register an individual account within Web API 2. It happens on the client.PostAsync. The api/account/register is not changed from what was created when creating teh Web API 2 project to use individual accounts.

var handler = new HttpClientHandler();
handler.UseDefaultCredentials = true;
handler.PreAuthenticate = true;
handler.ClientCertificateOptions = ClientCertificateOption.Automatic;

handler.Credentials = new NetworkCredential("<user>", "<pass>");

HttpClient client = new HttpClient(handler);
client.BaseAddress = new Uri("http://localhost/<dev_site>/");
client.DefaultRequestHeaders.Accept.Add(
        new MediaTypeWithQualityHeaderValue("application/json"));
var rbm = new RegisterBindingModel();
rbm.UserName = "<user>";
rbm.Password = "memememe";
rbm.ConfirmPassword = "memememe";

MediaTypeFormatter jsonFormatter = new JsonMediaTypeFormatter();.
HttpContent content = new ObjectContent<RegisterBindingModel>(rbm, jsonFormatter);

var resp = client.PostAsync("api/account/register", content).Result;


resp value = {StatusCode: 500, ReasonPhrase: 'Internal Server Error', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
  Pragma: no-cache
  Cache-Control: no-cache
  Date: Fri, 14 Mar 2014 14:32:49 GMT
  Server: Microsoft-IIS/7.5
  X-AspNet-Version: 4.0.30319
  X-Powered-By: ASP.NET
  Content-Length: 6065
  Content-Type: application/json; charset=utf-8
  Expires: -1
}}

我应该提到的另一件事是,它来自另一个连接到Web API应用程序的.NET MVC应用程序.我在Visual Studio中的调试过程中使用localhost和端口号尝试了完全相同的代码,并且在Web API项目的homecontroller中完全可以正常工作.因此,当从本地主机和Visual Studio调试器之外的本地主机调用它时,它会引发内部服务器错误,但在内部时,它会按预期工作.

The other thing I should mention is that this is coming from another .NET MVC application that is hooking into the Web API application. I tried the exact same code, using the localhost and port number during debugging while in visual studio, and it worked completely fine within the homecontroller of the Web API project. So it is throwing an internal server error when being called from the localhost outside of itself and the visual studio debugger but when inside of it, it is working as intended.

推荐答案

在运行Azure myTodo示例代码时遇到了相同的错误.通用错误非常令人沮丧.原来在服务器上的注册方法处发生了错误:

I ran into the same error while running Azure myTodo sample code. The generic error is very frustrating. It turns out the error occurred at register method on server:

 IdentityResult result = await this.UserManager.CreateAsync(user, model.Password);

如果在其周围添加try/catch块并进行调试,它将告诉您更多详细信息.就我而言,我收到如下错误消息:

If you add a try/catch block around it and debug through it, it will tell you more details. In my case, I got the error message like:

从 数据库.这可能是由于实体框架使用了不正确的 连接字符串.检查内部异常以获取详细信息并确保 连接字符串正确.

An error occurred while getting provider information from the database. This can be caused by Entity Framework using an incorrect connection string. Check the inner exceptions for details and ensure that the connection string is correct.

就我而言,这确实是一个连接字符串问题.

It is indeed a connection string problem, in my case.

这篇关于内部服务器错误api/帐户/注册的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆