【问题标题】:500 Server Error when calling RESTFUL (GET) Web API over HTTP通过 HTTP 调用 RESTFUL (GET) Web API 时出现 500 服务器错误
【发布时间】:2018-07-12 13:43:24
【问题描述】:

我在虚拟机内部有一个 Web 服务器,在其中有一个客户端。

对于服务器端,我使用的是 .NET Framework 4.6.1

这是我的 WEB API 控制器(服务器端)的结构:

// GET: api/Users
    public IQueryable<Users> GetUsers()
    {
        db.Configuration.ProxyCreationEnabled = false;

        return db.Users;
    }

    // GET: api/Users/5
    [ResponseType(typeof(Users))]
    public IHttpActionResult GetUsers(string id)
    {
        db.Configuration.ProxyCreationEnabled = false;
        Users users = db.Users.Find(id);
        if (users == null)
        {
            return NotFound();
        }

        return Ok(users);
    }

如果我在浏览器上(在虚拟机内)http://localhost:50347/api/Users/id IIS express 通过浏览器回复我(正确)。

客户端进行此调用(打字稿):

login(account: Account): Observable<Utente> { 
let apiURL = `${URL.LOGIN}/${account.username}`;                                                        
return this.http.get<Utente>(apiURL);                                                                   

这正是调用http://10.211.55.5/api/Users/id

如果我尝试直接在浏览器上调用http://10.211.55.5/api/Users/id,浏览器会给我这个“错误”:

此 XML 文件似乎没有任何与之关联的样式信息。文档树如下所示。

我希望有人可以帮助我。提前谢谢你。

【问题讨论】:

  • 您检查过 Windows 事件日志以查看是否记录了任何错误?
  • 嗨,这是我第一次在.net,我可以在哪里找到日志错误?因为从服务器端“似乎”一切正常..
  • that exactly call http://10.211.55.5/api/Users/id ?这意味着您正在尝试查找其主键值为字符串 id 的用户?在这种情况下,db.Users.Find 可能会抛出异常。 This XML file does not appear to have any style information associated with it. The document tree is shown below. 无论如何都不是错误消息,对于没有样式表链接的任何 XML 响应都会显示。
  • 您是否尝试过调试代码?您是否尝试过执行该操作或设置断点?调试时是否抛出异常?

标签: c# asp.net-mvc entity-framework rest typescript


【解决方案1】:

我找到了解决办法:

我修改了:

  1. 连接字符串从:integrated security=Trueuser id=user_id;password=your_password
  2. IIS 从 IIS expressIIS local

现在通信正常了。

我认为 IIS 试图通过 Windows 用户身份验证与数据库连接,因此(在 macOS 内部)存在(可能)权限问题。非常感谢。

【讨论】:

    猜你喜欢
    • 2014-08-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多