Hi,
I am able to get the built in restSettings for create,update,delete to work in IE but I encounter authorization problem in Chrome&Firefox.
I was able to get the datasource manually with angular and pass in withCredentials: true below.
is there a similar function i can use in IGniteui-angular2 iggrid?
Project:
.net core/ Angular 4/ Igniteui-angular2/ ignite ui 17.1
Angular:
getErrorTypes(): Observable<IErrorType[]> {
return this._http.get(this._errorTypesUrl, { withCredentials: true })
Error Message:
OPTIONS http://localhost/api/v1/CREERRORTYPES/1 401 (Unauthorized)
errortype:1 XMLHttpRequest cannot load http://localhost/api/v1/CREERRORTYPES/1. 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:35636' is therefore not allowed access. The response had HTTP status code 401.
Hello,
I believe that this is due to the same origin policy. Here's how to disable it in chrome.
Can you provide a sample for further investigations?
The cors headers are handled by the api. that's why it's throwing the second error message(CORS) because it failed to authorize w/ the API ( 401 (Unauthorized)). The API require windows authentication.
Please find my sample code attached. You will need to replace the API url with the API that require windows authentication.
I am able to pass in withCredentials as a request option and it will send below request header to the api. is there a similar way to do it in IGGRID built in rest function?
home.service.ts
getHome(): Observable<IHome[]> { return this._http.get(this._testUrl, { withCredentials: true }) .map((response: Response) => <IHome[]>response.json()) .do(data => console.log('All: ' + JSON.stringify(data))) .catch(this.handleError); }
Request Header:
Authorization:Negotiate YIIjpAYGKwYBBQUCoIIjmDCCI5SgMDAuB......
Replace URL:
home.service.ts(_testUrl)
home.component.ts(restSettings)
The restSettings of the grid do not provide setting fields of xhr. So it is not possible to set them through the options, but you can take of advantage of $.ajaxSetup by setting xhrFields - withCredentials for the web api url for create, update and delete settings. The easiest way to apply this is into the grid rendered event. I tried it on my side and to use the credentials I need to set the contentType of the restSettings to undefined.
Thanks, it works for me w/o setting the content type to undefined & i don't need to pass in the url in the ajax setup either.
$.ajaxSetup({ xhrFields: { withCredentials: true } }),
Awesome, glad to hear you got this working.