将asp.net核心角度应用程序部署到iis

时间:2020-10-14 14:15:08

标签: angular asp.net-core iis

我创建了一个ASP.NET Core Angular应用程序 Project Structure

我正在尝试将其部署到IIS中,但是有一些问题。 我将其上传到服务器中,但是正如您在控制台日志中看到的那样,如果进入“获取数据”选项卡this error appears

在localhost中,一切正常。我做了publish to folder之后 并将其上传到我的服务器,客户端无法通过HTTP访问它。

这是asp.net核心控制器功能:

@model VievModel.MyView

Return View("MyView", ratingConverter);

这是来自角度组件的HTTP get请求:

 [HttpGet("[action]")]
        public IEnumerable<Country> GetCountries()
        {
            List<Country> countries;
            var dictionary = new Dictionary<string, string>();

            try
            {
                var client = new RestClient("https://restcountries-v1.p.rapidapi.com/all");
                var request = new RestRequest(Method.GET);
                request.AddHeader("x-rapidapi-host", "restcountries-v1.p.rapidapi.com");
                request.AddHeader("x-rapidapi-key", "a75567071fmsh1da754f34ee180dp16140cjsnd0ce561437aa");
                IRestResponse response = client.Execute(request);

                countries = JsonConvert.DeserializeObject<List<Country>>(response.Content);

            }
            catch
            {
                string countriesJson = System.IO.File.ReadAllText("c:\\tmp\\countries.json");
                countries = JsonConvert.DeserializeObject<List<Country>>(countriesJson);
            }


            foreach (Country c in countries)
            {
                dictionary.Add(c.alpha3Code, c.name);
            }
            


            return Enumerable.Range(0, countries.Count - 1).Select(index => new Country
            {
                name = countries[index].name,
                capital = countries[index].capital,
                languages = countries[index].languages,
                timezones = countries[index].timezones,
                borders = countries[index].borders.Select(s => dictionary[s]).ToList(),
                flag = "https://www.countryflags.io/" + countries[index].alpha2Code + "/flat/64.png",
                population = countries[index].population,
                nativeName = countries[index].nativeName,
                currencies = countries[index].currencies,
                region = countries[index].region,
            });
        }

这也是.angular-cli.json文件:

 http.get<Country[]>(baseUrl + 'api/Countries/GetCountries').subscribe(result => {
      this.countreis = result;
      this.filterCountries = this.countreis;

      this.config = {
        itemsPerPage: 10,
        currentPage: 1,
        totalItems: this.countreis.length
      };


    }, error => console.error(error));

0 个答案:

没有答案