运行web api 项目时报403.14错误Web 服务器被配置为不列出此目录的内容,拒绝目录列表!!
查了资料也不知所以然,api的调试工具用的是Fiddler,输入地址依然没有动静。
web api 项目应该怎么测试呢?!!
//Controller代码段 namespace July27solution.Controllers { public class ValuesController : ApiController { private readonly List<Users> _userList = new List<Users> { new Users {UserID=1,UserName="hly",UserEmail="hly@qq.com"}, new Users {UserID=2,UserName="xzq",UserEmail="xzq@qq.com"}, new Users {UserID=3,UserName="hy",UserEmail="hy@qq.com"} }; // GET api/values public IEnumerable<Users> Get() { return _userList; } //根据主键得到实体 // GET api/values/5 public Users Get(int id) { return _userList.FirstOrDefault(i=>i.UserID ==id ); } // POST api/values public Users Post([FromBody]Users us) { _userList.Add(us); return us; } //FromBody表单对象 // PUT api/values/5 public Users Put(int id, [FromBody]Users us) { var user = _userList.FirstOrDefault(i=>i.UserID==id); if(user!=null) { user.UserName = us.UserName; user.UserEmail = us.UserEmail; } return user; } // DELETE api/values/5 public void Delete(int id) { _userList.Remove(_userList.FirstOrDefault(i=>i.UserID==id)); } } } //html代码段 <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> </head> <body> <fieldset> <legend>测试Web Api </legend> <a href="javascript:add()">添加(post)</a> <a href="javascript:update(1)">更新(put)</a> <a href="javascript:deletes(1)">删除(delete)</a> <a href="/api/values">列表(Get)</a> <a href="/api/values/1">实体(Get)</a> </fieldset> <script> function add() { $.ajax({ url: "/api/Test/", type: "POST", data: { "UserID": 4, "UserName": "test", "UserEmail": "Parry@cnblogs.com" }, success: function (data) { alert(JSON.stringify(data)); } }); } //更新 function update(id) { $.ajax({ url: "/api/Values?id=" + id, type: "Put", data: { "UserID": 1, "UserName": "moditest", "UserEmail": "Parry@cnblogs.com" }, success: function (data) { alert(JSON.stringify(data)); } }); } function deletes(id) { $.ajax({ url: "/api/Values/1", type: "DELETE", success: function (data) { alert(data); } }); } </script> </body> </html> //实体 namespace July27solution.Models { public class Users { public int UserID { get; set; } public string UserName { get; set; } public string UserEmail { get; set; } } }
iis的事情.跟webapi没关系
百度下怎么发布mvc项目.
恩恩,好的
呼叫每一個都回403.14?
是的