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

Discussion in 'ASP .Net' started by =?Utf-8?B?VmljdG9yIFNvbmc=?=, May 31, 2004.

  1. 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
    =?Utf-8?B?VmljdG9yIFNvbmc=?=, May 31, 2004
    #1
    1. Advertising

  2. =?Utf-8?B?VmljdG9yIFNvbmc=?=

    clintonG Guest

    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" <> wrote in message
    news:...
    > 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");
    > }
    >
    > rather than using something like ....
    >
    > if (FileStream.Length > 0)
    > {
    > //store stream in session variable and redirect to

    download page
    > Session.Add("UserDownload", FileStream);
    >

    Server.Transfer("Download.aspx?SessionVarName=UserDownload&DefaultFileNa
    me=JEPosting.csv");
    > }
    >
    >
    > Any help is really appreciated,
    > Victor
    >
    clintonG, Jun 1, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. gaurav tyagi
    Replies:
    14
    Views:
    1,320
    gaurav tyagi
    Jan 20, 2006
  2. Replies:
    0
    Views:
    870
  3. John Kennedy
    Replies:
    5
    Views:
    221
    Carl Prothman [MVP]
    Aug 14, 2003
  4. John Kennedy
    Replies:
    5
    Views:
    435
    Carl Prothman [MVP]
    Aug 14, 2003
  5. Jim
    Replies:
    1
    Views:
    872
    Aaron Bertrand - MVP
    Jan 28, 2004
Loading...

Share This Page