发布数据时找不到404错误

时间:2019-06-26 06:25:51

标签: angular

我有一个角度应用程序,我正在尝试使用.net Web Api发布数据 但是每当我发布数据时,它都会给我这个错误消息

:39506 / api / EmployeeAli:1无法加载资源:服务器以404(未找到)状态进行响应

我几乎尝试了所有事情,从制作代理到调用api 启用cors,但没有任何作用

这是我的angular应用程序服务类中的调用Web api的方法:  postEmployee(formData:Employee){

  /*first parameter is url for the PostEmployee method in our 
    web api the second parameter is form data which will be passed to the 
    variable employee of model class Employee of webapi*/

 return this.http.post(this.Web Api Url +'/Employee',formData);
}

employee.component.ts中的此方法正在调用此服务类方法

insertRecord(form:NgForm){

   this.service.postEmployee(form.value).subscribe(res=>{
   this.resetForm(form);

   this.service.refresh List();
  });

}

在我的Web APi中,我在web config.cs和控制器中都启用了cors:

  namespace Angular 7 CRUD Web Api.Controllers
 {
   [EnableCors("http://localhost:4200", headers: "*", methods: "*")]
   public class EmployeeController : ApiController

此代码来自我的Wep ApiConfig文件:

    var cors = new EnableCorsAttribute("http://localhost:4200", "*", "*");
         config.EnableCors(cors);
        // Web API routes
        config.MapHttpAttributeRoutes();

        config.Routes.MapHttpRoute(
            name: "DefaultApi",
            routeTemplate: "api/{controller}/{id}",
            defaults: new { id = RouteParameter.Optional }

发布时,它应该在数据库中添加数据,但是没有发生,并且给我错误404

0 个答案:

没有答案
相关问题