javascript

Make Monorail return right content-type header

Posted on Март 6, 2008. Filed under: .net, asp, Castle project, coding, javascript, Monorail |

Recently I had a task of adding some drag and drop abilities to a layer, representing chat window on a web page. Users can move it and resize it. I knew it to be a hard javascript task because the solution had to be crossbrowser. So I chose javascript library by walterzorn for it’s great customization features and fully documented process of installation. Using it is like this:

  <script type="text/javascript">  <!--

SET_DHTML('chat-window'+CURSOR_MOVE+RESIZABLE+TRANSPARENT+MINWIDTH+200+MINHEIGHT+150);  //-->

</script>  </body></html>

As you can see we are using only div layer Id to make it dragndroppable and also we use a set of predefined global constants that allow us to use some new abilities. Isn’t it great, you guys? But the installation documentation mention the fact this awesome library work only in HTML, not in XHTML (that’s really a contra with a lot of modern websites) because it uses document.write() which is not supported by XHTML specification. That’s why I needed my website to send Content-type: text/html header so that Firefox, Opera, Safari and others could use html 4.01 specification.. One can ask himself: why not using doctype and meta tag to specify specification (sorry for that one recursion)? The point is, those browsers judge the document by Content-Type header. Using great LiveHttpHeaders plugin for firefox I found out that there is application/xhtml+xml header returned from server. It turns out that if in Web.config I have

<viewEngines v iewPathRoot="Views">

<add xhtml="true" type="Castle.MonoRail.Framework.Views.NVelocity.NVelocityViewEngine, Castle.MonoRail.Framework.Views.NVelocity" />

then View layer of Monorail overrides any headers that I try to give it using Response.ContentType = «text/html»

The solution that makes monorail return «text/html» header is to set xhtml attribute to false. You still may not manipulate headers in arbitrary manner, but you can customize the behaviour choosing between «application/xhtml+xml» and «text/html».

Читать запись полностью | Make a Comment ( None so far )

Liked it here?
Why not try sites on the blogroll...