Currently I have all ajax request that send Authentication token, but I created a service to export to excel, ajax doesn't support that and I am using location.href for the get request. Is there any way to add that token?
var getUrl = '/LandingView/ExportToExcel?excelHeader=' + excelHeader;
getUrl += '&companyId=' + $scope.options.companyId;
getUrl += '&startDate=' + $scope.options.startDate.toJSON();
getUrl += '&endDate=' + $scope.options.endDate.toJSON();
getUrl += '&page=' + $scope.options.page;
getUrl += '&stateFilter=' + $scope.options.stateFilter;
getUrl += '&rows=' + $scope.options.rows;
getUrl += '&alertFilter=' + $scope.options.alertFilter;
getUrl += '&mode=' + $scope.options.mode;
getUrl += '&showLanguages=' + $scope.options.showLanguages;
location.href = getUrl;
When I do this I need to include in the header the bearer token.
PS: I am using ASP.NET MVC in the backend and angularJS in the frontend.
I found an article that helped my for good. I will set the link over here.
The idea of this approach is that you can do with ajax, then return the file name saved in temp folder with a guid generated name, and with that file name download the file with location.href, finally delete the file.
https://www.codeproject.com/Tips/1156485/How-to-Create-and-Download-File-with-Ajax-in-ASP-N
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.