【发布时间】: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