Avatar of optimus376
optimus376

asked on 

HttpContext Wierd Values

I writing out the content to HTTP response and I’m adding the header type as CSV. The exports works fine in local, QA and staging but in production I see a hex value at the beginning and 0 at the end. Since I’m not able to reproduce the same in local or QA I’m having a hard time debugging this. Have any of you seen this before ?

This is how I’m writing to response stream. The UI makes an http post to the ExportCSV.

                              [HttpPost]
             public void ExportCSV()
             {
HttpContextBase context = HttpContext;
                           context.Response.Clear();
                           context.Response.ContentType = "text/csv";
                           context.Response.AddHeader("Content-Disposition", "attachment; filename=" + "xxx" + Guid.NewGuid().ToString() + ".csv");
            context.Response.Write("XXXXX”);
                          context.Response.End()
}


This is what I’m seeing in the export

22d (Hex value proportional to content length)

Data

0
ASP.NETC#Microsoft IIS Web Server

Avatar of undefined
Last Comment
optimus376
SOLUTION
Avatar of MajorBigDeal
MajorBigDeal
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of optimus376
optimus376

ASKER

Thanks MajorBigDeal. The data is actually coming from UI. The server side just formats the data and returns the reponse as csv. Do you think forcing

Response.ContentType = "text/csv; charset=utf-8"; will help ?
ASKER CERTIFIED SOLUTION
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of MajorBigDeal
MajorBigDeal
Flag of United States of America image

It might help, I'm not sure.  One thing that would be good to know is if the difference in in the actual string coming from the UI, or if the difference is being introduced when the string is processed for output.  That would be a big clue as to what is going on.
Avatar of optimus376
optimus376

ASKER

I changed the function return type as FileResult and returned a File(stream, filename) and it magically fixed things. THanks :)
Avatar of optimus376
optimus376

ASKER

I've requested that this question be closed as follows:

Accepted answer: 0 points for optimus376's comment #a38745750

for the following reason:

Found the solution myself
ASP.NET
ASP.NET

The successor to Active Server Pages, ASP.NET websites utilize the .NET framework to produce dynamic, data and content-driven web applications and services. ASP.NET code can be written using any .NET supported language. As of 2009, ASP.NET can also apply the Model-View-Controller (MVC) pattern to web applications

128K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo