Tag: asp.net web api

Azure Active Directory – 为什么浏览器没有注册而不是第一方应用程序?

我们安装了Windows Azure Active Directory来保护Web API。 Web API公开了一个OData3端点,它工作得很好。 现在我正试图用Excel连接到这个odata端点。 这是行不通的。 我也find了答案,例如在这个堆栈溢出post: WAAD身份validation与Excel PowerQuery消耗的WebAPI OData服务 基本上问题是: AAD今天不支持第三方服务(您的服务)authentication的第一方客户端(PowerQuery)。 但希望很快就足够:)也许只是当你得到rest完成:)! Okey,我知道你需要在Azure Active Directory中注册任何客户端应用程序,如果你想访问AAD保护的web api或web应用程序。 但是,我真的没有得到:任何浏览器,我可以validation受保护的资源? 为什么这个工作,我的意思是我没有注册浏览器,但他们实际上只是一个客户端! 我可以使用任何浏览器对我的服务进行身份validation,但使用Excel则无法正常工作。 为什么? 也许我搞砸的东西,但一些解释将是真正有用的解决我的节点:) 最好提前感谢Laurin

Excel文件通过web api下载。 腐败

我试图通过Web API(使用entity framework)下载一个Excel文件。 下载正在工作,但我正在尝试打开文件时出现一些关于文件损坏的错误对话框。 Web API代码如下: public HttpResponseMessage GetValue(int ID, string name) { MemoryStream stream; try { using (DataContext db = new DataContext()) { dynamic fileObj = (from c in db.FileList c.ID == IDc).ToList(); stream = new MemoryStream(fileObj(0).File); HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK); result.Content = new StreamContent(stream); result.Content.Headers.ContentType = new MediaTypeHeaderValue(fileObj(0).FileContentType); result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") […]

将Excelfile upload到Web API

我正在尝试上传一个excel文件到我的WebApi和DO STUFF的内容。 我有extJs部分通过完成上传button发送文件。 (代码如下) 我的问题是我不知道如何build立webApi部分来处理excel文件。 我猜我必须有一个HttpPost。 假WebApi: public string SampleUploadFile() { return _repo.UploadFile(); } Extjs代码: xtype: 'form', //renderTo: 'fi-form', //(5) fileUpload: true, //(1) width: 500, frame: true, title: 'Position Sheet Upload Form', bodyPadding: '10 10 0', //bodyStyle: 'padding: 10px 10px 0 10px;', defaults: { anchor: '100%', allowBlank: false, msgTarget: 'side', labelWidth: 50 }, //labelWidth: 50, […]

WebAPI和angularJS JS文件下载 – 文件损坏

我在我的WebAPI中生成一个Excel文件。 我将它“存储”在一个内存stream中,然后放入响应中,如下所示: var result = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StreamContent(ms) }; result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = projectName + ".xlsx" }; // ms.Close(); return result; 它看起来像服务器端正在工作正确。 如果我正在将该内存stream写入文件stream,则会创build该文件并可以毫无问题地打开该文件。 在angular度方面,如何在点击button时重新创build文件? 我尝试了这样的事情: $scope.exportQuotas = function (projectName) { homeService.GetQuotas(projectName, $routeParams.token, $scope.selection).then( function (data) { var dataUrl = 'data:application/octet-stream;' + data var link […]

在Angularjs和WebApi中下载Excel文件xlsx

我正在做一个任务,在这个任务中,我必须以xlsx格式下载报告。 报告文件从服务器成功生成,也在客户端接收。 但是它没有打开并生成无效的格式错误。 以下是服务器端的代码。 var output = await reportObj.GetExcelData(rParams); if (output != null){ var result = new HttpResponseMessage(HttpStatusCode.OK) { Content = new ByteArrayContent(output.ConentBytes) }; result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = output.FileName }; return result; } 这里是客户端的代码: var saveData = function (response) { if (response.status === 200) { var reportData = […]

通过WebApi调用从页面下载excel文件

我试图发送一个9MB的.xls文件作为从Web API控制器方法的响应。 用户将点击页面上的button,这将通过浏览器触发下载。 这是我到目前为止,但它不起作用,但它也不会抛出任何例外。 [AcceptVerbs("GET")] public HttpResponseMessage ExportXls() { try { byte[] excelData = m_toolsService.ExportToExcelFile(); HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK); var stream = new MemoryStream(excelData); result.Content = new StreamContent(stream); result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = "Data.xls" }; return result; } catch (Exception ex) { m_logger.ErrorException("Exception exporting as excel file: ", […]

MemoryStream似乎在NPOI workbook.write后closures?

我正在使用NPOI将DataTable转换为ASP.NET Web API项目中的Excel。 但是,我没有收到任何回应。 这是我的代码: public HttpResponseMessage GetExcelFromDataTable(DataTable dt) { IWorkbook workbook = new XSSFWorkbook(); // create *.xlsx file, use HSSFWorkbook() for creating *.xls file. ISheet sheet1 = workbook.CreateSheet(); IRow row1 = sheet1.CreateRow(0); for (int i = 0; dt.Columns.Count > i; i++) { row1.CreateCell(i).SetCellValue(dt.Columns[i].ColumnName); } for (int i = 0; dt.Rows.Count > i; i++) { […]