问题描述
我创建了一个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));
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)