所以我有一个问题,就是返回仅在IE中发生的文件后,没有设置cookie。
逻辑如下:
在两种情况下 2 :由于设置了cookie,页面应显示一条消息-但是,仅在文件失败时返回一条消息,而在返回文件下载时不显示该消息。 / p>
我的代码如下:
public ActionResult MyAction(string parm) {
if (parm != null) {
// generate file and message
byte[] generatedFile = GenerateCsvFile(parm, out bool success, out string message);
// Set cookie with message saying it failed or succeeded
Response.Cookies.Add(new HttpCookie("downloadedFile", message) {
Expires = DateTime.Now.AddSeconds(60)
});
if (success) { // return file for user to download
return File(generatedFile, "text/csv", "MyDocument.csv");
}
return new HttpStatusCodeResult(204); // do nothing because it failed
}
// Initial view load
return View();
}
这是怎么回事,我该如何解决?
答案 0 :(得分:0)
返回文件时的结果消息中包含的字符无效,无法放入IE可读的cookie(但可被Chrome,Firefox等读取)。
因此,解决方法是在将其设置为cookie之前对其进行URL编码。
Function SuperSearcherTHING(ivalue As Variant, theColumn As Range) As String
Dim rCell As Range
Const theSPACER As String = "|"
For Each rCell In Intersect(theColumn.EntireColumn, theColumn.Worksheet.UsedRange).Cells
If InStr(1, rCell.Value, ivalue, vbTextCompare) > 0 Then
SuperSearcherTHING = rCell.Value & theSPACER & SuperSearcherTHING
End If
Next rCell
SuperSearcherTHING = Left(SuperSearcherTHING, Len(SuperSearcherTHING) - Len(theSPACER))
End Function