- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个操作将 Excel 作为自定义 FileResult 返回。我的解决方案基于 ClosedXml库(内部使用 OpenXml)。我的 XlsxResult 类使用服务器上的只读 .xlsx 文件作为模板。然后,它将模板传递到内存流中,并使用 ClosedXml 对其进行操作和保存。最后,内存流被写入响应。
这在 Cassini 和 IIS Express 上都可以正常工作,但在部署在 azure 上时会失败,并且没有任何错误。我遇到的唯一影响是发送到服务器的请求永远不会得到任何响应。我仍在等待 60 分钟左右的事情发生......
我的行动:
[OutputCache(Location= System.Web.UI.OutputCacheLocation.None, Duration=0)]
public FileResult Export(int year, int month, int day) {
var date = new DateTime(year, month, day);
var filename = string.Format("MyTemplate_{0:yyyyMMdd}.xlsx", date);
//return new FilePathResult("~/Content/templates/MyTemplate.xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
var result = new XlsxExportTemplatedResult("MyTemplate.xlsx", filename, (workbook) => {
var ws = workbook.Worksheets.Worksheet("My Export Sheet");
ws.Cell("B3").Value = date;
// Using a OpenXML's predefined formats (15 stands for date)
ws.Cell("B3").Style.NumberFormat.NumberFormatId = 15;
ws.Columns().AdjustToContents(); // You can also specify the range of columns to adjust, e.g.
return workbook;
});
return result;
}
我的文件结果
public class XlsxExportTemplatedResult : FileResult
{
// default buffer size as defined in BufferedStream type
private const int BufferSize = 0x1000;
public static readonly string TEMPLATE_FOLDER_LOCATION = @"~\Content\templates";
public XlsxExportTemplatedResult(string templateName, string fileDownloadName, Func<XLWorkbook, XLWorkbook> generate)
: base("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") {
this.TempalteName = templateName;
this.FileDownloadName = fileDownloadName;
this.Generate = generate;
}
public string TempalteName { get; protected set; }
public Func<XLWorkbook, XLWorkbook> Generate { get; protected set; }
protected string templatePath = string.Empty;
public override void ExecuteResult(ControllerContext context) {
templatePath = context.HttpContext.Server.MapPath(System.IO.Path.Combine(TEMPLATE_FOLDER_LOCATION, this.TempalteName));
base.ExecuteResult(context);
}
//http://msdn.microsoft.com/en-us/library/office/ee945362(v=office.11).aspx
protected override void WriteFile(System.Web.HttpResponseBase response) {
FileStream fileStream = new FileStream(templatePath, FileMode.Open, FileAccess.Read);
using (MemoryStream memoryStream = new MemoryStream()) {
CopyStream(fileStream, memoryStream);
using (var workbook = new XLWorkbook(memoryStream)) {
Generate(workbook);
workbook.Save();
}
// At this point, the memory stream contains the modified document.
// grab chunks of data and write to the output stream
Stream outputStream = response.OutputStream;
byte[] buffer = new byte[BufferSize];
while (true) {
int bytesRead = memoryStream.Read(buffer, 0, BufferSize);
if (bytesRead == 0) {
// no more data
break;
}
outputStream.Write(buffer, 0, bytesRead);
}
}
fileStream.Dispose();
}
static private void CopyStream(Stream source, Stream destination) {
byte[] buffer = new byte[BufferSize];
int bytesRead;
do {
bytesRead = source.Read(buffer, 0, buffer.Length);
destination.Write(buffer, 0, bytesRead);
} while (bytesRead != 0);
}
}
那么我是否错过了一些东西(显然我错过了)。
请注意:
坦克。
UPDATE:After I logged extensively in my code the execution hangs with no error at the ClosedXml "Save" method call. But still no error. Abstract from the WADLogsTable:
- Opening template file from path:E:\sitesroot\0\Content\templates\MyTemplate.xlsx
- Opened template from path:E:\sitesroot\0\Content\templates\MyTemplate.xlsx just
- copied template to editable memory stream. Bytes copied: 15955,Position: 15955
- modified the excel document in memory.
- here it hangs when a it calls to workbook.Save(); This is a ClosedXml method call.
最佳答案
我遇到了和你完全相同的错误情况。我无法针对您的具体情况提供解决方案,并且我知道您改变了方向,但是在经历了您所面临的相同令人沮丧的步骤之后,我想为您(或其他人)的答案“铺平道路” .
进入 Visual Studio 中的包管理器控制台并使用 MVC 功能(路由)安装 Elmah:
Install-Package elmah.MVC
现在,在您的根 web.config 中,更新您的 Elmah 条目。它可能位于文件末尾,如下所示:
<elmah></elmah>
更新那个坏男孩以允许远程访问并设置您的日志路径:
<elmah>
<security allowRemoteAccess="1" />
<errorLog type="Elmah.XmlFileErrorLog, Elmah" logPath="~/app_data/elmah" />
</elmah>
现在,将其推送到 Azure。
最后,访问您的网站,强制出现错误,然后导航至 http://your-site-here.azurewebsites.net/elmah您将看到错误的确切原因。
Elmah 太棒了。
胆怯的坦白:我的错误不在第三方代码中,结果是在我的连接字符串中,我没有为其设置MultipleActiveResultsSets
为真。我必须做的另一个修复是在调用 ToList() 到该库上的一个内部方法之后将我的实体传递给该库,将其保留为 IQueryable 中断该方法。
关于azure - Azure 上的自定义 FileResult : Browser Waits forever,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12094389/
在 Firefox 扩展的 Javascript 中,您可以调用 gBrowser.getBrowserForTab但是没有gBrowser.getTabForBrowser .所以我写了自己的并且它
在问这个可能含糊不清的问题之前,我搜索了 SO,发现许多对“现代浏览器”的引用,但没有定义。由于这是一个被广泛使用和引用的术语,令我惊讶的是我在 Internet 上找不到定义甚至描述。 那么,在 2
更新:老问题仅适用于 IE11 预览版;浏览器模式在 IE11 最终版本中回归。但有一个问题:它几乎没有用,因为它不模拟条件注释。例如,如果您使用它们在旧版 IE 中启用 HTML5 支持,您将无法再
我的移动页面和短信有问题:链接。该页面主要由基于 Android 和 iOS 的智能手机通过 QR 扫描应用程序访问。 特别是在 iPhone 上,有一些带有集成浏览器的 QR 应用程序(webkit
我想使用 CustomTabsIntent。但是我没有找到androidx的customTabs路径和版本。 最后我得到了这个:androidx.browser:browser:1.0.0 我想知道正
我想将来自不同域(支付提供商)的 ssl 安全页面加载到 iframe 中。据我所知,一些(或全部?)浏览器会在页面的某些部分受到保护而其他部分不安全时警告用户。 这是真的吗? 如果是这样,如果主站点
在 Protractor 中,有 browser.pause() function : Beta (unstable) pause function for debugging webdriver t
我可以使用以下方法检索浏览器日志 browser.manage().logs().get('browser').then(function(browserLog) { logger.info('
当使用 protractor 时,全局变量 browser 似乎具有 browser.driver 的所有功能。 我特地问这个是因为我不确定是使用 browser.wait 还是 browser.dr
面对 Protractor 的计时问题。有时我的 Protractor 测试用例会因网络或性能问题而失败。我已经解决了 browser.sleep() 的现有问题。后来知道了browser.wait(
我仍然无法找到解决此问题的方法。我们有一个启动浏览器窗口的应用程序,但我们使用的底层第三方插件尚不支持 IE9。我知道我可以通过点击 F12 并选择它来切换到 IE8 的浏览器模式。 有没有办法在命令
在 Protractor 脚本中,我总是遇到超时问题,即使我设置了很大的 time out jasmine interval、allscripttimeout...在某些地方,我不得不等到元素出现,比
我正在运行一个 Angular 应用程序,并且在 Protractor 上测试时尝试获取当前 URL。使用哪一个? browser.driver.getCurrentUrl() 或 browser.g
“所有浏览器兼容”和“跨浏览器兼容”有什么区别? “交叉”是什么意思,是指不同的操作系统吗? 如果任何网站在 IE 7、8 FF 3+、Safari 3+ 的桌面版本上运行良好,我们可以说它是跨浏
不明白浏览器同步中的错误阅读文档,其中 gulp 4 真的没有写任何关于它的内容。在 gulp 4 的文档中也没有理解(异步)。如何解决这个问题。谢谢。 bla bla bla bla bla bla
我正在尝试在 ASP.Net C# 代码隐藏中执行“如果浏览器是 IE 且版本低于 9”。 但是,在 chrome 中,以下行: if (Request.Browser.Browser == "IE"
我第一次玩 watir,使用 this site作为指导。我在一个简单的程序(如下)中遇到错误 - 它在第一个非要求行失败,如图所示。 如果我没有运行下面显示的内容,而是删除了该行,它会打开一个空的
下面的 if 条件我认为它是说 - 如果浏览器是 IE 并且 IE 浏览器版本高于 9,但我没有 IE 9 来测试它,所以很难知道正确的输出,这也是不是 100% 的我想要的 bcos 默认情况下该脚
我通过 Pingdom 测试了我的网站并得到了这个: 我进行了搜索,但找不到解决方案。有谁知道我怎样才能得到这个14到100? 最佳答案 不是一个完整的解决方案,但您可以通过将两个请求合并为一个来改善
是否可以禁用浏览器/窗口之间的 HTML5 拖放功能? 我正在使用具有 native HTML5 拖放功能的 Angular2 应用程序,并希望防止用户将其拖动到浏览器窗口之外并防止将可拖动对象拖放到
我是一名优秀的程序员,十分优秀!