Sto scrivendo una semplice pagina di test per scaricare un file di testo in un browser sul pulsante clic. Sto ottenendo un errore davvero strano che non ho mai visto prima. qualche idea?ASP.Net Scarica il file sul browser del client
L'errore si verifica su 'Response.End();' e il file non viene mai al browser del client
Codice:
string filePath = "C:\\test.txt";
FileInfo file = new FileInfo(filePath);
if (file.Exists)
{
Response.ClearContent();
Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
Response.AddHeader("Content-Length", file.Length.ToString());
Response.ContentType = "text/plain";
Response.TransmitFile(file.FullName);
Response.End();
}
Errore:
Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack.
rimuovere la fine e provare Responce.Flush() e Responce.ApplicationInstance.CompleteRequest(); – Aristos
Una buona chiamata, che ha bloccato l'eccezione dall'essere lanciata. Ma il codice si completa ancora senza che nulla avvenga sul browser. ?? – tier1