Server.Transfer working for IIS 5.1 but not for IIS 6.0

G

Guest

Hi

We are trying to stream a file using server.transfer rather than response.redirect. We have it working for IIS 5.0 but IIS 6.0 refusing to let us transfer the file. If we do the less efficient prompt/response technique to the browser both work fine.

We found this article that was only slightly appicable (ms-help://MS.MSDNQTR.2004APR.1033/enu_kbiis/iis/326965.ht
kb 326965 ) but since csv is already a defined mime type this shouldn't be an issue

Is there some type of security setting or some other trick to get it working with IIS 6.0?

Here are some code snippets
private void Page_Load(object sender, EventArgs e

//get query string parameter
string QSSessionVariableName = Request.QueryString["SessionVarName"]
string DefaultFileName = Request.QueryString["DefaultFileName"]
if (DefaultFileName.Length == 0) DefaultFileName = "output.csv"

if (QSSessionVariableName.Length > 0

string OutputStream = (string) Session[QSSessionVariableName]
if (OutputStream.Length > 0

Response.Clear()
Response.AddHeader("Content-Disposition", "attachment; filename=" + DefaultFileName)
//Response.AddHeader("Content-Length", OutputStream.Length.ToString())
Response.ContentType = "application/x-csv"
Response.Write(OutputStream)
Response.Flush()
Response.End()

els
System.Diagnostics.Debug.Assert((OutputStream == null || OutputStream.Length == 0),"Output stream is empty")

els
System.Diagnostics.Debug.Assert((QSSessionVariableName == null | QSSessionVariableName.Length == 0),"Stream Variable Name is not passed from QueryString")


rather than using something like ...

if (FileStream.Length > 0

//store stream in session variable and redirect to download pag
Session.Add("UserDownload", FileStream)
Server.Transfer("Download.aspx?SessionVarName=UserDownload&DefaultFileName=JEPosting.csv")


Any help is really appreciated
Victo
 
C

clintonG

The ASP.NET Server.Transfer method is different than that of ASP
as it includes an overload related to the ViewState to identify one of
several considerations. You'll need to delve into documentation [1]
and while there study the Page class looking at the Context property
that provides access to the HttpContext object for the current request,
i.e. HttpContext.Handler and HttpContext.Items.

My MCAD training guide states we can not pass a QueryString in
the URL with the Server.Transfer method which I remain confised
about myself as this little test harness [2] allowed me to pass a Query
String from PageTransfer_Sender.aspx to PageTransfer_Target.aspx.

--
<%= Clinton Gallagher
A/E/C Consulting, Web Design, e-Commerce Software Development
Wauwatosa, Milwaukee County, Wisconsin USA
NET csgallagher@ REMOVETHISTEXT metromilwaukee.com
URL http://www.metromilwaukee.com/clintongallagher/

[1]
http://msdn.microsoft.com/library/d...temWebHttpServerUtilityClassTransferTopic.asp

[2] string qs;

private void Page_Load(object sender, System.EventArgs e)
{
qs = "?qs=" + txtQueryString.Text;
}
....
private void btnTransfer_Click(object sender, System.EventArgs e)
{
Server.Transfer("PageTransfer_Target.aspx" + qs);
}


Victor Song said:
Hi,

We are trying to stream a file using server.transfer rather than
response.redirect. We have it working for IIS 5.0 but IIS 6.0 refusing
to let us transfer the file. If we do the less efficient
prompt/response technique to the browser both work fine.
We found this article that was only slightly appicable (ms-help://MS.MSDNQTR.2004APR.1033/enu_kbiis/iis/326965.htm
kb 326965 ) but since csv is already a defined mime type this shouldn't be an issue.

Is there some type of security setting or some other trick to get it working with IIS 6.0?

Here are some code snippets:
private void Page_Load(object sender, EventArgs e)
{
//get query string parameters
string QSSessionVariableName = Request.QueryString["SessionVarName"];
string DefaultFileName = Request.QueryString["DefaultFileName"];
if (DefaultFileName.Length == 0) DefaultFileName = "output.csv";

if (QSSessionVariableName.Length > 0)
{
string OutputStream = (string) Session[QSSessionVariableName];
if (OutputStream.Length > 0)
{
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=" + DefaultFileName);
//Response.AddHeader("Content-Length", OutputStream.Length.ToString());
Response.ContentType = "application/x-csv";
Response.Write(OutputStream);
Response.Flush();
Response.End();
}
else
System.Diagnostics.Debug.Assert((OutputStream == null ||
OutputStream.Length == 0),"Output stream is empty");
}
else
System.Diagnostics.Debug.Assert((QSSessionVariableName == null
| QSSessionVariableName.Length == 0),"Stream Variable Name is not passed
from QueryString");
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top