How to forward a 'saved' request stream to another Action within the same controller?

We have a need to chunk-up large http requests sent by our mobile devices. These smaller chunk streams are merged to a file on the server. Once all chunks are received we need a way to submit the saved merged request to an another method(Action) within the same controller that will process this large http request. How can this be done? The code we tried below results in the service hanging. Is there a way to do this without a round-trip?

//Open merged chunked file FileStream fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read); //Read steam support variables int bytesRead = 0; byte[] buffer = new byte[1024]; //Build New Web Request. The target Action is called "Upload", this method we are in is called "UploadChunk" HttpWebRequest webRequest; webRequest = (HttpWebRequest)WebRequest.Create(Request.Url.ToString().Replace("Chunk", string.Empty)); webRequest.Method = "POST"; webRequest.ContentType = "text/xml"; webRequest.KeepAlive = true; webRequest.Timeout = 600000; webRequest.ReadWriteTimeout = 600000; webRequest.Credentials = System.Net.CredentialCache.DefaultCredentials; Stream webStream = webRequest.GetRequestStream(); //Hangs here, no errors, just hangs

I have looked into using RedirectToAction and RedirecctToRoute but these methods don't fit well with what we are looking to do as we cannot edit the Request.InputStream (as it is read-only) to carry out large request stream.


You can build what you want, save in the TempData, RedirectToAction and there pull it from the 'TempData'

something like this:

public ActionResult DoSomething()
var data = GetData();
TempData["Data"] = data;


public ActionResult Forward()
var data = TempData["data"];
if (data == null)
throw new ArgumentException("data is null");

// Do your magic.


Found what I was looking for here: Needed to perform the following steps:

1) Create File stream to read the merged chunk from file
2) Create new System.Net.HttpWebRequest with destination URI
3) Copy Header from original request to new requested noted in 2)
4) Copy contents from file stream to new request
5) Set the content-lenght of new request to the lenght of the file stream
6) Close both file stream and new request streams
7) Copy Headers from original to new request
8) Copy Cookies from original to new request

So basically its the same logic one could use when programming ASP.NET stuff. mvc Time:2011-11-27 Views:0
Tags: mvc

Related post

Copyright (C), All Rights Reserved.

processed in 0.526 (s). 13 q(s)