C# - How To Get Response.ContentType / "text/csv" Causes XML Error
Aug 5, 2010
I've got an odd issue.I'm creating a DataTable type my application then converting it to a CSV so the user can download the data.
I set the content type like this:
context.Response.Clear();
context.Response.ContentType = "text/csv";
context.Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName + ".csv");
var responseBuilder = new StringBuilder(data.Rows.Count * data.Columns.Count * 30);
Now, this works well for all data sizes in my development environment, and for small amounts of data on my production environment, but when it gets to a larger size (say, more than about 4000 rows) on production Firefox gives me the error:
We are running ASP.NET MVC on IIS6. We have started to notice a problem with IE8 clients. Almost all the time, the ContentType returned is 'text/html' but occasionally, it will be returned as 'application/xhtml+xml'. This is causing IE8 to try and download the file instead of rendering the contents in the browsers.
Where is the ContentType set in the ASP.NET/MVC pipeline?
I'm using VirtualPathProvider and VirtualFile to send some Assembly Resource. The files are plain text files and I need to garantee that MIME "application/xml", "text/plain" or something like gets to the client Content-Type Response.Header.
I've tried setting:
[Code]....
But, still, "application/octet-stream" reaches the client side.
how to set ContentType on a VirtualPathProvider/VirtualFile scenario?
I'm writing an application that needs to map two different stores into different properties of the same entity. Basically, we have a CMS that exposes a file list PDF's via a web service. We have to send it an XML request and the response contains the data that needs to be parsed into each entity. 'm not sure how to modify the model in this way though. I can think of two ways to handle this,1. Create a new Schema that uses something like the System.Xml.Provider for each different request type/result set2. Write a partial class for the Entity and populate all the unmapped fields using serialized XML I'm actually unsure how to actually do either of the above, but if someone knows a good starting point or a better way to go about this please let me know. This is my first MVC project and so I'm not completely up to speed on all the concepts/best pracise.
I have got an error "server response error : Unknown server error" while uploading file using Ajax AsyncFileUpload, code behind function is triggered while uploading, but after code behind function executed, we are getting this error.
Simple upload has been working for quite a while now, yet it seems to all the sudden not work (but only for specific file types). mp3 can upload, flv cannot (remember, this was all working before).After a little debugging, I discovered that a portion of my code is never being entered because I test something first:
[Code]....
I have discovered that resourceMediaFile.PostedFile is not null, resourceMediaFile.PostedFile.ContentLength is the correct size for the uploaded file, yet resourceMediaFile.PostedFile.ContentType is now null. I've literally had this work over 1,000 times with several files (including the one I'm testing with) and it consistently came back "application/flv".
What would cause ContentType to be null if the other attributes are not?
I want to return a response with type text/plain and status code 404. How do I do that? I've found that ContentResponse allows for setting response type but how do I set response status code?
As security of the return data is not a problem, I am Get enabling the HTTP response. On the client (browser) end, my code is as below
[Code]....
Everything works smoothly but occasionally on the web server's event viewer, I see the following error
"Request format is unrecognised for URL unexpectedly ending in /SomeWebServiceWebMethod"
After fiddling through the request headers using Fiddler, I figured out that if I make direct request to the webservice link, contentType header attribute is missing and that is what throws the error. There is a good post by scott guthrie explaining this. I am not able to replicate the issue and not sure what removes the contentType attribute from the request header occasionally.
I am generating a pdf file to a MemoryStream, and then using Response.BinaryWrite to display that in the browser. But if a pdf reader is not installed, then I get an ugly error message.
Is there something I can do so that if no pdf reader is installed, I can display a friendly message or provide the option to save the file to the system?
I am using VB to upload image files to my server but am having problems. How can I use the ContentType to filter only image files? This is my code for my upload button which does not seem to be working. I can only upload bmp files:
[Code]....
Also, how can I show the user the image they uploade
I have a problem with the Ajax ComboBox from the Ajax Control ToolKit. When I want to erase the text in the ComboBox, I got this error:
"Microsoft JScript runtime error: '_optionListItems[...].text' is null or not an object". I only get this error when deleting the content of the Combox is the first action I do on the ComboBox. If I overwrite the text by entering something else before deleting this text, I got no error.
I'm using localReport to print PDF (SQL REPORTVIEWER). It works fine on localhost. When I move the application to Production (64 bits windows 2008) it gives me an error. (see below)
I put the renderedbytes in a Session in USERCONTROL and I do window.open('Program1.aspx')...
In page load of Program1.aspx I try to retrieve the Session variable and process.... I think this statement cause the error "Response.BinaryWrite (...) etc".
It works on my local pc (Vista 32bits)...
[Code]....
Server Error in '/' Application. Object reference not set to an instance of an object. Description: An unhandled exception occurred during the execution of the current web request. review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
I have a collection of links I response.redirect to the first one. if the first one errors with page 404 ie page does not exist i want to redirect to the next one. If the next one errors I then want to redirect to the one after etc. Basically go through the collection and redirect to a link that doesnt error with page 404 error. is this possible in .net 2?
it works fine when i run it in debug mode, but gives the following error when running through IIS Problems during Load Problems came up in the following areas during loadMissing file: QTnicFLJ5JKZN8dyEzUEsK2jPtygbkw....
First of all, quickly what exactly I want to achieve: translate particular exception into the HTTP 404 so the ASP.NET can handle it further. I am handling exceptions in the ASP.NET (MVC2) this way:
protected void Application_Error(object sender, EventArgs e) { var err = Server.GetLastError(); if (err == null) return; err = err.GetBaseException(); var noObject = err as ObjectNotFoundException; if (noObject != null) HandleObjectNotFound(); var handled = noObject != null; if (!handled) Logger.Fatal("Unhandled exception has occured in application.", err); } private void HandleObjectNotFound() { Server.ClearError(); Response.Clear(); // new HttpExcepton(404, "Not Found"); // Throw or not to throw? Response.StatusCode = 404; Response.StatusDescription = "Not Found"; Response.StatusDescription = "Not Found"; Response.Write("The whole HTML body explaining whata 404 is??"); }
The problem is that I cannot configure default customErrors to work with it. When it is on then it never redirects to the page specified in customErrors: <error statusCode="404" redirect="404.html"/>. I also tried to raise new HttpExcepton(404, "Not Found") from the handler but then the response code is 200 which I don't understand why. So the questions are:
1-What is the proper way of translating AnException into HTTP 404 response? 2- How does customErrors section work when handling exceptions in Application_Error? 3- Why throwing HttpException(404) renders (blank) page with success (200) status?
This might be a silly question, how do you usually response to errors? Response with one error at a time or Response with multiple errors at a time, in a list record
Example
Invalid Email Address format Invalid Phone number format Invalid Password .etc... Invalid API credentials
I'm facing a small issue,I have two usercontrols. In Usercontrol1, I have a public method Load(), In my second usercontrol, UserControl2, I call this mehtod like this:
[code]
Kindly let me know how I can solve this issue.Would be great if you can support your response with necessary code.
Sys.Webforms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled. Details: Error parsing near ' i have kept button in updatepanel and i am getting this error