当我从 Visual Studio 运行或浏览它时,我已经构建了一个 ASP.NET Web API,它工作正常,但是当我在 IIS 中托管它并尝试浏览它时它不起作用并给我以下错误:HTTP 400 错误不是你,是这个链接(好像坏了)在这里我发布我的网络服务API方法是 [HttpGet] [Route("findall")] public HttpResponseMessage findAll() { try { var response = new HttpResponseMessage(HttpStatusCode.OK); response.Content = new StringContent(JsonConvert.SerializeObject(mde.Products.ToList())); response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); return response; } catch { return new HttpResponseMessage(HttpStatusCode.BadRequest); } }我向它发送以下请求:http://localhost:9810/api/product/findall我该如何解决这个问题?
2 回答

拉风的咖菲猫
TA贡献1995条经验 获得超2个赞
根据屏幕截图,您已将应用程序部署为默认站点上的虚拟应用程序。并且/myserver被定义为虚拟路径。这意味着您的 API 根 URL 将是:
http://localhost:{IIS_PORT}/myserver/{YOUR_APP_ROUTES}
默认网站端口为 80;如果您帖子中的 URL ( http://localhost:9810/api/product/findall ) 在 IIS-express 上正常工作,请尝试为您的 IIS 部署调用此 URL:
http://localhost/myserver/api/product/findall

萧十郎
TA贡献1815条经验 获得超13个赞
在命令提示符下执行此命令
%windir%\Microsoft.NET\Framework\v4.0.21006\aspnet_regiis.exe -i
对我来说它解决了这个问题
- 2 回答
- 0 关注
- 214 浏览
添加回答
举报
0/150
提交
取消