Setting Content - Type Of Empty Response In MVC

Dec 27, 2010

In order to support a legacy application that's in the field, I need my ASP.NET MVC app to return an empty response that also has a Content-Type. One of IIS, ASP.NET, or ASP.NET MVC is removing my Content-Type when I send back a null response. Is there any way around this? (While not requiring an empty response with a set Content-Type would obviously be the ideal solution, the clients are already out there, and many of them cannot be upgraded.)

EDIT: Since there was a request for code: I'm proxying the request from the new web application to the one that older clients rely on. To do this, I have a subclass of ActionResult, called LegacyResult, that you can simply return for those methods that need to be handled by the old software. This is the relevant part of its code:

public override void ExecuteResult(ControllerContext context)
{
using (var legacyResponse = GetLegacyResponse(context))
{
var clientResponse = context.HttpContext.Response;
clientResponse.Buffer = false;
clientResponse.ContentType = legacyResponse.ContentType; /* Yes, I checked that legacyResponse.ContentType is never string.IsNullOrEmpty */
if (legacyResponse.ContentLength >= 0) clientResponse.AddHeader("Content-Length", legacyResponse.ContentLength.ToString());
var legacyInput = legacyResponse.GetResponseStream();
using (var clientOutput = clientResponse.OutputStream)
{
var rgb = new byte[32768];
cb;
while ((cb = legacyInput.Read(rgb, 0, rgb.Length)) > 0)
{
clientOutput.Write(rgb, 0, cb);
}
clientOutput.Flush();
}
}
}

If legacyInput has data, then Content-Type is set appropriately. Otherwise, it's not. I can actually kluge the old backend to send an empty v. non-empty response for exactly the same request, and observe the difference in Fiddler.

EDIT 2: Poking around with Reflector reveals that, if headers have not been written at the time that HttpResponse.Flush is called, then Flush writes out the headers itself. The problem is that it only writes out a tiny subset of the headers. One of the missing ones is Content-Type. So it seems that, if I can force headers out to the stream, I can avoid this problem.

View 1 Replies


Similar Messages:

WCF / ASMX :: Content Type Text / Html Of The Response Message Does Not Match The Content Type Of The Binding

May 7, 2010

I'm getting this message when going to a web app that accesses my service.

"The content type text/html of the response message does not match the content type of the binding (text/xml; charset=utf-8)..."

The thing is, it happens once in a while even when no changes have been made to the service or the web app. And I can make it go away most of the time by going directly to the .svc?wsdl page in my browser and then coming back to the web app.

View 2 Replies

Web Forms :: Setting All Text Box On A Form To Empty?

Feb 24, 2010

I have a C# 2008 asp.net form, and I need to call a function that will clear all text boxes on the page.

How can I go about doing that (the code for looping thru the textboxes on the webpage, and setting them to empty) ?

View 9 Replies

JQuery Ajax Request Response Is Empty In Internet Explorer?

Jan 4, 2011

I'm doing the following ajax call:

[code]....

jQuery ajax request response is empty in Internet Explorer?

View 1 Replies

Why Is Cookie Available In Request Immediately After Setting Using Response

Aug 4, 2010

In pageload, if you do Response.Cookies.Add(..., immediately in the next line, you can access that cookie via Request.Cookies(... I know that under the covers, the cookie is added to Request.Cookies by .net, but the original request never had that cookie.

If what I'm saying is correct, why is it this way? Shouldn't the cookie be available in the following request? Shouldn't the immediate access to Request.Cookies(... be null?

View 1 Replies

IIS 7.5 HttpModule - Setting Response.Filter Results In Chunked Encoding?

Feb 8, 2011

I'm trying to create a HttpModule that changes the Response.Filter like so(for this demonstration just set the filter back to itself):

public class ContentTrafficMonitor : IHttpModule
{
public void Init( HttpApplication context )
{
context.BeginRequest += OnBeginRequest;[code]....

Doing so sets the transfer encoding of the response to chunked, rather than using the Content-Length header.If I remove the line where the Response.Filter is set, the response does have the Content-Length header. Our application depends on the Content-Length header, is there any way to prevent this behavior?

View 1 Replies

Check Whether DateTime Data Type Variable Is Null / Empty?

Oct 6, 2010

How i do check whether DateTime data type variable is null/empty in asp.net ?

View 5 Replies

Response.Content Open In New Window?

Sep 15, 2010

I have a button that when clicked on it will open a pdf file in the current window. Can someone help me modify my code to open in a new window? Here's what I have so far that works when the button is clicked:

[Code]....

View 3 Replies

MVC :: Providing File Content As A URL Response?

Jun 25, 2010

I hope this is a ridiculously simple problem. In my ASP.NET MVC web application, I have several places where the appropriate response to the {whatever}/Detail/{#} URL is the binary content of a file that lives outside of the installed application, with an appropriate ContentType in the header.I don't_ want to expose the directory containing the files or its contents as files to the web. That would make it possible to browse other files by educated guessing and would require special work to interact well with the authorization mechanism.I _do_ want HTTP response to contain the content stream of the file corresponding to the supplied ID, so that it will result in the usual open or save-to-file stuff in the browser. The client should have no clue as to where the content originates I can imagine a solution where I write code in my controller to open streams and feed the output to the response, taking the HttpResponse by the throat and forcing it to skip the master page and forcing the content type. I'm already doing something similar
to dump some log content into a support page.However, ASP.NET MVC is a strong framework and this has got to be a pretty common situation. Is there a kinder, gentler way to do this already provided by the platform, either through routing or in my controller? At first blush, I didn't see an ActionResult for this. I do see that returning something other than an ActionResult will cause the object supplied to be rendered as content, which sounds like what I want. However, what sort of object should I return to do this for a whole file, perhaps a relatively large.

View 1 Replies

WCF / ASMX :: Change Response Type In WSE 3.0 Service

Mar 24, 2011

I inherited a old WSE 3.0 service. I am building an ASP.NET client for it. It is returning a MTOM response so my client is complaining. Does anyone know of a way to change the response type to XML? Or change my client to accept MTOM? I just want this crap to work.

View 2 Replies

How To Apply The Response.redirect Command To Have The Content

Jun 9, 2010

How do I apply the response.redirect command to have the content of what I a url that I fetch displayed in my web app. I fetch the url and since vb.net is not recognizing response.redirect I am a little stumped. I have a textarea where I display the responsestream which works but I would like it displayed the same way it displays in a browser. The pages source has a lot of javascript functions so I am not sure if this is even relevant.

View 1 Replies

How To Configure IIS To Serve 404 Response With Custom Content

Mar 31, 2010

I would like to serve a custom 404 page from ASP.NET MVC. I have the route handler and all the infrastructure set up to ensure that nonexistent routes are handled by a single action:

public ActionResult Handle404()
{
Response.StatusCode = 404;
return View("NotFound");
}

Problem: IIS serves back its own content (some predefined message) when I set Response.StatusCode to 404 before returning the content.

On the VS development web server, this works as intended - the status code of the HTTP response is 404 while my content (the NotFound view) is served.

I believe that when the IIS processing pipeline sees that the application returns 404, it simply replaces the whole response with its own.

What setting in IIS affects this behavior?

I do not have access to the IIS installation so I can not investigate this - however, I can ask the hosting provider to tweak the configuration for me if I know what exactly needs to be changed.

View 1 Replies

Setting The ScriptManager AsyncPostBackTimeout Value On The .NET Content Page?

Jan 14, 2011

I am using Master pages for my ASP.NET website and in one of the content pages I upload a file which requires a bigger timeout value than the default 90 seconds. for other content pages I want to leave the default timeout value as it is. is it possible to set the timeout just for a specific content page? I checked the ScriptManagerProxy component, but it doesn't have this AsyncPostBackTimeout property.

View 1 Replies

MVC :: Modifying Response Content After Controller Action Executed?

Mar 18, 2011

Is there a way of modifying the response in OnResultExecuted? Like reading the current response and writing it out again?

I want to replace date string in JsonResult after the object was serialized.

View 6 Replies

Web Forms :: Response.Write Output To A Content Placeholder?

Mar 18, 2010

the response.write() output does not show in content placeholder but on top of the page.

[Code]....

View 6 Replies

MVC :: Want To Return A Response With Type Text/plain And Status Code 404?

Jul 26, 2010

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?

View 2 Replies

Changing Response Type In Aspx Page Breaks In IIS7?

Mar 3, 2010

I have a custom implementation of Application_PreRequestHandlerExecute which is applying a deflate/gzip filter to the response. However, on IIS7, this is failing on my "script generator" pages. These aspx pages take in Query String values and return a custom bit of script, changing the response type to text/javascript. I think it is failing because of the way iis7 uses mime types, but I'm unsure how to fix it short of turning all compressio off.

View 1 Replies

Web Forms :: Couple Of Content Place Holders On A Master Page Which By Default Are Empty?

Mar 1, 2010

This is my scenario. I have a couple of content place holders on a Master page which by default are empty.Two of the content place holders are laid out side by side. I'll call one MainContent and the other SidebarContent. What I'd like to see happen is if a child page has content in the SidebarContent, the width of the MainContent should be adjusted accordingly.Is there a way to determine at runtime from the Master page if the calling child page has populated the SidebarContent?How do I go about this, if possible?

View 1 Replies

Setting A Server Control Property From The Content Page?

Oct 27, 2010

I need to validate a textbox to ensure the submit date is older than Today. I wanted to use a CompareValidator to do that, but unfortunately the following code doesn't work:

<asp:CompareValidator ID="cvtbDateExpiration" ControlToValidate="tbDateExpiration"
Operator="GreaterThan" Type="Date" ValueToCompare="<%= DateTime.Today %>"
ErrorMessage="Card has expired" runat="server" />

The compiler tells me that ValueToCompare="<%= DateTime.Today %>" is wrong: "This is not scriptlet. Will be output as plain text."

Is there a simple way to achieve this (without setting it using the Code Behind)?

View 1 Replies

AJAX :: Setting The ScriptManager AsyncPostBackTimeout Value On The .NET Content Page?

Jan 14, 2011

I am using Master pages for my ASP.NET website and in one of the content pages I upload a file which requires a bigger timeout value than the default 90 seconds. for other content pages I want to leave the default timeout value as it is. is it possible to set the timeout just for a specific content page? I checked the ScriptManagerProxy component, but it doesn't have this AsyncPostBackTimeout property.

View 1 Replies

Web Forms :: Setting Default Button For Asp:content Page

Mar 20, 2010

how to set default button for a asp:Content.

I tried using the panel , but it is not working.

In one of my content page , i have two divs - div1,div2.

On page load , only the div1 will be visible. On clicking a button inside it the div1 is made to invisible and the second div- div2 is made visible.

At the page load , i want to make the button inside the div1 to be the default one. On its click i want to make the button inside the div2 to be the default one .How can i do that?

View 4 Replies

Web Forms :: Setting Up Each Of TabPanels.ContentTemplates To Be Content Placeholder

Mar 8, 2010

Is there a benefit from putting a Tabcontainer control on a master page and setting up each of the tabPanels.ContentTemplates to be a content placeholder rather than putting everything into a regular .aspx page?

View 3 Replies

Web Forms :: Content Page - Setting Accept Button

May 12, 2010

I wish to set the accept button for each of my content pages. My Master Page login button is set as the accept button somehow. This is fine for the home page, but not the majority of the other 40 pages. All of my website pages are content pages and they are linked to the master page. They don't have forms, just contentplaceholder tags. Does anyone know if there is a way to programaticaly set the accept button in the code behind of a content page?

View 2 Replies

Web Forms :: Setting Relative TabIndex For A Content Page?

Feb 24, 2011

Just posting this up as I've been searching all over the net for the last few hours and not found anything useful. What I need to do is set the tabindex on a content page so that when using keyboard navigation the form controls in one vertical column are selected first, and then the 2nd column. (rather than one row at a time).

My problem is this means that the "skip to content" and all the other links in the master page are bypassed and the first form control with a tabindex!=0 is jumped to. Is there any way to set the tabindex on a content page relative to the previous tabindex from the masterpage? (when no tabindex is set on the master page).

I was hoping at the top of the content page you could set relativetabindex or something like. we use many different masterpages that change fairly frequently so setting the tab index for every control on the page is a really horrible way to get round this. I'm hoping theres a nice .Net way of doing it and no javascript hacking has to be done!

View 8 Replies

Web Forms :: Remove HTML Content And New String In The Response Object?

Feb 22, 2010

How can I remove the html content and add new string to the Response object. If I use the Respose.Write method the page contains the string, but while taking the view source option from browser it will display some html tag like Doctype, head, body etc. My requirement is only the string should be displayed in the source.

View 2 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved