我有一個FileStreamResult操作,它使用iTextSharp打開一個PDF文檔(CAD繪圖),在它上面貼上我們公司的信息,然後將它傳遞給要返回的內存流。MVC Filestream多次調用
在方法內部我有一個審計方法,通過實體框架將事務記錄到SQL。當我打電話給我時,我得到三個數據庫事務。調試應用程序時會三次擊中SQL記錄函數。
任何人都可以幫我理解爲什麼嗎?這是否與路由有關?
編輯我做了一些進一步的測試,發現當我直接訪問瀏覽器時,它只調用一次該方法。我正在使用jQuery和.PDFObject(www.pdfobject.com)在另一個視圖中呈現PDF。這個jQuery方法三次調用MVC方法。我仍在調查...
public class DrawingsController : BaseController
{
static BaseFont ...
public FileStreamResult Index(string WOBase, string WOSub)
{
//Get associated drawing by work order
WorkOrders WO = db.WorkOrders
.Where(wo => wo.DRAWING_FILE != null && wo.BASE_ID == WOBase && wo.SUB_ID == WOSub)
.FirstOrDefault();
if (!string.IsNullOrEmpty(WO.DRAWING_FILE))
{
//The following records the transaction history (x3)
BaseController.RecordNavigation(_employee.ID, "Print", WO.Drawing_URL);
string readerURL = modifyPathToURL(WO.DRAWING_FILE);
Response.Clear();
MemoryStream ms = new MemoryStream();
PdfReader reader = new PdfReader(readerURL);
PdfStamper stamper = new PdfStamper(reader, ms);
for (int i = 1; i <= reader.NumberOfPages; ++i)
{
var stamperOverContent = stamper.GetOverContent(i);
//Stamp information on document
...
stamperOverContent.EndText();
stamperOverContent.RestoreState();
}
stamper.Writer.CloseStream = false;
stamper.Close();
byte[] byteinfo = ms.ToArray();
ms.Write(byteinfo, 0, byteinfo.Length);
ms.Position = 0;
ms.Seek(0, SeekOrigin.Begin);
return new FileStreamResult(ms, "application/pdf");
}
return null;
}