如何使用angularJS

时间:2017-01-13 06:29:03

标签: angularjs asp.net-web-api

您好我已经开发了一个小的web api crud应用程序并托管在IIS服务器中。我能够完成所有操作。我托管在服务器192.168.0.213:7777,它工作正常。我试图通过angularjs从另一个应用程序访问这些服务,如下所示。

 this.deleteSubscriber = function (user_id) {
        var url = 'http://192.168.0.213:7777/api/User_Creation/' + user_id;
        return $http.delete(url).then(function (response) {
            return response.data;
        });
    }

每当我尝试删除用户时,我都会收到如下错误消息。

Failed to load resource: the server responded with a status of 405 (Method Not Allowed)
XMLHttpRequest cannot load http://192.168.0.213:7777/api/User_Creation/37. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:26079' is therefore not allowed access. The response had HTTP status code 405.

我可以知道为什么我会遇到这个问题吗?我需要在iis或我的应用程序中进行任何更改吗?谢谢......

1 个答案:

答案 0 :(得分:4)

您可以通过配置customHeaders

在iis8中启用CORS
Route::group(array('prefix'=>'admin','middleware' => 'auth_admin_check'), function() {
    Route::any("dashboard",["as"=>"admin_login_post1","uses"=>"admin\DashboardController@index"]);
});

也可以在代码级别配置 - Enabling Cross-Origin Requests in ASP.NET Web API 2