2017-06-10 11 views
-1

ASPネットコアのWebアプリケーション配備見つかりません:アクセスウェブAPI 404の後、私は二つのプロジェクト含まVS 2017でソリューションを作成

  • 1 - Web APIを
  • 2 - Visual Studio ASP .NETでのコアWebアプリケーションを角度サービスを介してWebApiコントローラに送信します。

私は1つのWeb APIをコントローラ

[Route("api/[controller]/[action]")] 
public class ClientController : Controller 
{ 
    // GET: api/Client/Get 
    [HttpGet] 
    public JsonResult Get() 
    { 
     ClientQuery _Query = new ClientQuery(); 
     List<ClientLisModel> _Results = _Query.GetAll(); 

     return new JsonResult(_Results); 
    } 

と私は、このコントローラのアクションにアクセスするための関数を作成し、私の角度サービスで持っている:私は自分のアプリケーションを実行したときにすべてが正しく動作

this.getListeClient = function getListeClient() { 
      var deferred = $q.defer(); 

       $http({ 
        method: 'GET', 
        url: '/api/Client/Get' 
       }) 
        .then(function (data) { 
         deferred.resolve(data); 
        }) 
        .catch(function (msg, code) { 
         deferred.reject(msg); 
         $log.error(msg, code); 
        }); 

       return deferred.promise; 
      } 

を2017年から。しかし、私はiis 7.5のMyWebSiteにそれを配備します。私はこのエラーがあります:

GET http://localhost/api/Client/Get 404 (Not Found)

それはhttp://localhost/MyWebSite/api/Client/Get

私のWeb.configファイルがあるためになります。

<?xml version="1.0" encoding="utf-8"?> 
<configuration> 
    <system.webServer> 
    <handlers> 
     <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" /> 
    </handlers> 
    <aspNetCore processPath="dotnet" arguments=".\Application.UI.Web.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" /> 
    </system.webServer> 
</configuration> 

ありがとう!

答えて

0

この問題の解決策は、anuglarモジュールでconfigを使用することです。

は、だから私の角度のjsモジュールでは、私はこの行を追加します。

(function() { 
    'use strict'; 

    angular.module('clientApp', ['ui.bootstrap', 'smart-table']); 

    angular.module('clientApp').constant('config', { 
     apiUrl: 'http://localhost:55555', 
     baseUrl: '/', 
     enableDebug: true 
    }); 
})(); 

を、私はこのように私のjsの角度サービスを変更:

angular 
     .module('clientApp') 
     .service("clientService", function (config, $http, $q) { 
      this.getListeClient = function getListeClient() { 
       var deferred = $q.defer(); 

       $http({ 
        method: 'GET', 
        url: config.apiUrl + '/api/Client/Get' 
       }) 
        .then(function (data) { 
         deferred.resolve(data); 
        }) 
        .catch(function (msg, code) { 
         deferred.reject(msg); 
         $log.error(msg, code); 
        }); 

       return deferred.promise; 
      } 

自分のアプリケーションを公開した後、私はちょうど「apiUrl」を変更しますmu angularjsモジュール。