dimanche 15 mars 2015

Prepend/Append content to a MVC FileStreamResult


Vote count:

0




I'm re-factoring some code which uses an handler (ashx) to use an MVC FileStreamResult instead.


The code returns json, but wraps it in a callback if jsonp is requested. (callback is a string some thing similar to "jQuery1112077" etc)



//existing
context.Response.AddHeader("Content-Type", "text/javascript");
if (format == "json")
{
context.Response.WriteFile(jsonFilePath);
}

if (format == "jsonp")
{
context.Response.Write(callback + "(");
context.Response.WriteFile(jsonFilePath);
context.Response.Write(")");
}

//MVC
if (format == "json")
{
Stream stream = new FileStream(jsonDocPath, FileMode.Open, FileAccess.Read);
FileStreamResult fs = new FileStreamResult(stream, "text/javascript");
return fs;
}


What is the most efficient "MVC" way of prepending and appending to the output stream for my jsonp case.



asked 1 min ago

Tim

1,837






Prepend/Append content to a MVC FileStreamResult

Aucun commentaire:

Enregistrer un commentaire