من این کنترولر رو نوشتم اما وقتی به آدرس api/comment میرم هیچی باز نمیشه
public IEnumerable<string> Get() { return new string[] { "value1", "value2" }; } // GET: api/Comment/5 public string Get(int id) { return "value"; } //// POST: api/Comment public bool Post(string key,string comment) { if (key == Key) { try { CommentServiceModel rsm = new CommentServiceModel(); rsm = JsonConvert.DeserializeObject<CommentServiceModel>(comment); Comment r = new Comment(); r.Comment1 = rsm.Message; r.Name = rsm.Name; r.DateTime = DateTime.Now; db.Comments.Add(r); db.SaveChanges(); return true; } catch (Exception e) { return false; } } else { return false; } } //PUT: api/Comment/5 public void Put(int id, [FromBody]string value) { } // DELETE: api/Comment/5 public void Delete(int id) { }
public static void Register(HttpConfiguration config) { config.MapHttpAttributeRoutes(); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); }
چک کنید در Global و در رویداد Application_Start کد کانفیگ WebApi وجود داشته باشد
هیچ کاربری تا کنون از این پست تشکر نکرده است
با ما تماس بگیرید تا در این مسیر همراهتان باشیم :)