Some background
I'm currently working on a mobile site so I keep switching user agent all the time in Firefox with User Agent switcher (lovely addon). But when I go to the admin site it renders as WML, which makes Firefox all confused, so it tries to download it rather then showing the content. And this makes me frustrated (not falling down frustrated, but enough!).
What I want!
How can I make our admin site to ALWAYS send content as text/html
instead of WML, regardless of request user-agent?
I have full control of the box. It's IIS 6.0.
We had this, and since we are using razor with html, the pages can't adapt automatically. For me, the simplest fix was to change the content-type in the _ViewStart.cshtml
:
Response.ContentType = "text/html";
The "figure out the content-type yourself" insanity only happens when nothing is set explicitly. So... set it.
Your actual views can still override this:
@{
Layout = null;
Response.ContentType = "application/atom+xml";
}
For info, to test for this issue on your local dev server (with a clean cache to avoid false results by previous cached data), do something like wget or Fiddler:
wget yourpage --header="Accept: text/vnd.wap.wml" --server-response --header="Accept-Encoding: gzip, deflate"
and look for:
Content-Type: text/vnd.wap.wml; charset=utf-8
in the result; if you see that, IIS/ASP.NET has decided to pretend your reply satisfies the request's "Accept" header... even if it doesn't. Worse: you might now be able to get that "text/vnd.wap.wml" from a wget without specifying the Accept header (or specifying something like "text/html"); if you see this you have a problem (or: your users do) - you have a cached response for WAP that is being fed to non-WAP clients.
With the above tweak, the first wget will return "text/html" - since that is what our content is. Sorry, down-level browsers; you should have included "text/html" as an option - and if you can't handle "text/html"... sucks to be you.
If you want a no-code/no-aspx change, you can add a browser capabilities file into the folder App_Browsers directly under your application root (if the folder's not there, just create it). To disable WML, simply put a file named ForceHtml.browser (anything ending in .browser) containing the following XML:
<browsers>
<browser refID="Default">
<capabilities>
<capability name="preferredRenderingMime" value="text/html" />
<capability name="preferredRenderingType" value="html32" />
<capability name="preferredImageMime" value="image/gif" />
<capability name="tagwriter" value="System.Web.UI.HtmlTextWriter" />
</capabilities>
<controlAdapters markupTextWriterType="System.Web.UI.HtmlTextWriter" />
</browser>
</browsers>
using iis7. putting this is global.asax did the trick:
void Application_OnUpdateRequestCache() {
if (Response.ContentType == "text/vnd.wap.wml") {
Response.ContentType = "text/html";
}
}
hth
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With