[英]Angular 2 loading local json file 403 forbidden error
Seems so simple from examples I see on the web but when I try to load a local json file from my Angular 2 application inside my service.ts, I get a 403 forbidden error. 从我在网上看到的示例看来如此简单,但是当我尝试从我的Angular 2应用程序中的service.ts中加载本地json文件时,出现了403禁止错误。 My application runs inside a Servicestack selfhosted service. 我的应用程序在Servicestack自托管服务中运行。 Works fine when I do a request like http://localhost:8087/customers/ but the same data inside a local json file in my app directory will not ( http://localhost:8087/app/customers.json ) 当我执行类似http:// localhost:8087 / customers /之类的请求时,工作正常,但我的应用程序目录中本地json文件中的相同数据将不起作用( http:// localhost:8087 / app / customers.json )
What do I have to do to allow my application to access that file? 我该怎么做才能允许我的应用程序访问该文件?
this._http.get('app/customers.json').toPromise()
.then(function (response) {
console.log(JSON.stringify(response))
}).catch(this.handleError);
Suggestion from @mythz fixed my issue. @mythz的建议解决了我的问题。 I added this line in my appHost file. 我在appHost文件中添加了这一行。
HostConfig.Instance.AllowFileExtensions.Add("json");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.