How can I set the default text / html content type in my web.config?

I would like to set the default content type for web pages in an ASP.NET MVC application for text / html.

I know this can be done by adding ContentType = "text / html" to all my <% pages%>, but I would rather use web.config instead. How can i do this?

Thanks,

Adrian

Edit: I know that โ€œtext / HTMLโ€ is the default ASP.NET standard, but for unknown reasons, Opera is still trying to parse my website as XHML unless I explicitly set the content type to my <% Page%> .

+4
asp.net-mvc web-config
source share
4 answers

We had the same problem, and the problem for us was that the mobile.browser file received from CodePlex has an error that forces asp.net to always indicate the version of the operating system on the desktop that we send xhtml. I deleted the mobile.browser file and solved the problem. It seems that the only thing we could find to redefine the directive on the part of mobile.browser was to specify ContentType = "text / html" for each kind of tag <% @ Page%>. Even setting the content type in global.asax had zero difference.

UPDATE: I found that removing all feature nodes named "preferredRenderingMime" from the mobile.browser file will fix these problems and still allow us to identify mobile browsers.

+8
source share

You can do this programmatically in Global.asax.cs in the Global_BeginRequest event handler:

protected void Application_BeginRequest(Object sender, EventArgs e) { HttpContext.Current.Response.ContentType = "text/html"; } 

FYI, the docs say that "text / HTML" is the default ASP.NET standard: http://msdn.microsoft.com/en-us/library/ms525208(VS.85).aspx

+1
source share

The content type for aspx views is already set to text/html .

 Content-Type: text/html; charset=utf-8 
+1
source share

"text / html" is the default value for this property in the HttpResponse object.

If you do not need to install it on anything else, do nothing. To set it to a different default value, you may need to create a base class for the page that sets the property and inherits from it.

+1
source share

All Articles