MVC3 Passing ControllerContext for streaming?

I use Rotativa in my MVC3 application to generate PDF files in a memory stream, which is then sent via email as an email attachment. This works fine, but it is rather slow (~ 5-7 seconds with one user), so I tried to put it in a separate thread so that the user would not get stuck with a huge delay.

The problem that I encountered is that Rotativa requires the Context Controller to generate data in the memory stream, which means that if you try to put it in a separate stream and return a notification to the user, then the context and creation of the pdf file will fail .

Unfortunately, I check the server side email authentication and return true / false, if necessary, false will prompt the user to fix the error and try again. This means that I can’t just assume that the letter is always valid (I could do it using jquery, but if they disable it and try to send, they will not receive an error message).

So far I have tried:

  • Create a new stream and transfer context to
  • Duplicate context by copying it to a new variable
  • Serialization of the context, transferring the stream to a new stream and de-serialization (unfortunately, the context is not serializable)

Does anyone have any other ideas?

+4
source share
1 answer

Here is what I am doing to start a long process in the background using context. I am using user sessions supported by the database. You will need to pass any values ​​you need into the "background" action.

using (var client = new WebClient()) { var values = new NameValueCollection { { "sessionid", DataSession.Id.ExtractSid() } }; client.UploadValuesAsync(new Uri(Url.AbsoluteAction("ResultsCallback", "Quote")), values); } 
0
source

All Articles