抛出HttpResponseException时出错

时间:2014-01-25 02:49:16

标签: c# iis asp.net-web-api2

我正在尝试返回状态代码,说明当用户不在数据库中时找不到用户

[Route("api/users/user")]
public User GetUser(String username)
{
    HttpRequestMessage request = new HttpRequestMessage();
    user result = unitOfWork.UserRepository.Get(u=>u.username == username).FirstOrDefault();

    //If the user doesn't exist
    if (result == null) throw new HttpResponseException(HttpStatusCode.NotFound);

    User user = new User();

    //Initialize the user
    user.user_id = result.user_id;
    user.username = result.username;
    user.password = result.password;
    user.email = result.email;

    return user;

   }

但是我收到了这个错误:

  

处理HTTP请求导致异常。请参阅   此响应的'Response'属性返回的HTTP响应   细节例外。

enter image description here

这是我发送的回复

{StatusCode: 404, ReasonPhrase: 'Could not find username: ImNotaRealUser', Version: 1.1, Content: System.Net.Http.StringContent, Headers:
{
  Content-Type: text/plain; charset=utf-8
}}

有谁知道为什么?

谢谢

修改

它只发生在我的笔记本电脑上。这是IIS的问题吗?

0 个答案:

没有答案