<?xml version="1.0" encoding="UTF-8"?> <rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
> <channel><title>MattAustin.me.uk &#187; asp.net</title> <atom:link href="http://mattaustin.me.uk/category/asp-net/feed/" rel="self" type="application/rss+xml" /><link>http://mattaustin.me.uk</link> <description>Python, Django, open source, Linux, and other internet shenanigans</description> <lastBuildDate>Thu, 19 Jan 2012 00:37:32 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.1</generator> <item><title>Serving the Correct MIME Type for XHTML using ASP.NET 2.0</title><link>http://mattaustin.me.uk/2006/11/serving-the-correct-mime-type-for-xhtml-using-asp-net-2-0/</link> <comments>http://mattaustin.me.uk/2006/11/serving-the-correct-mime-type-for-xhtml-using-asp-net-2-0/#comments</comments> <pubDate>Tue, 31 Oct 2006 16:00:46 +0000</pubDate> <dc:creator>Matt</dc:creator> <category><![CDATA[asp.net]]></category> <guid
isPermaLink="false">http://mattaustin.me.uk/?p=207</guid> <description><![CDATA[This example code goes some way to serving XHTML properly, as outlined in the article: Serving the Correct MIME Type for XHTML. Idealy, text/html should only be served when the user agent specifies acceptance of text/html, but not application/xhtml+xml. However, Internet Explorer 6 does not return anything useful in it&#8217;s HTTP_ACCEPT response. Place the following [...]]]></description> <content:encoded><![CDATA[<p>This example code goes some way to serving XHTML properly, as outlined in the article: <a
href="/2006/11/serving-the-correct-mime-type-for-xhtml/" title="Article on Serving the Correct MIME Type for XHTML">Serving the Correct MIME Type for XHTML</a>.</p><p>Idealy, <code>text/html</code> should only be served when the user agent specifies acceptance of <code>text/html</code>, but not <code>application/xhtml+xml</code>. However, Internet Explorer 6 does not return anything useful in it&#8217;s <code>HTTP_ACCEPT</code> response.</p><p>Place the following code in the <code>Page_Init</code> section of your master page:</p><pre>
String strContentType = null;
// Determine if the user agent returns any AcceptTypes (HTTP_ACCEPT) response
if (Request.AcceptTypes != null)
{
  // Determine if the user agent can handle XHTML served as &quot;application/xhtml+xml&quot; (e.g. FireFox, Opera)
  if (Array.IndexOf(Request.AcceptTypes, &quot;application/xhtml+xml&quot;) &gt; -1)
  {
    strContentType = &quot;application/xhtml+xml&quot;;
  }
  else
  {
    // If the user agent does not specifiy acceptence of &quot;application/xhtml+xml&quot;, then serve as &quot;text/html&quot; (e.g. Internet Explorer)
    strContentType = &quot;text/html&quot;;
  }
}
else
{
  // If AcceptTypes is null, then serve as &quot;application/xhtml+xml&quot; (e.g. W3C Validator)
  strContentType = &quot;application/xhtml+xml&quot;;
}
// Set the Response Content Type
Response.ContentType = strContentType.ToString();
if (strContentType == &quot;text/html&quot;)
{
  // Generate a &quot;content-type&quot; meta tag in the page head
  HtmlMeta hmtContentType = new HtmlMeta();
  hmtContentType.HttpEquiv = &quot;content-type&quot;;
  hmtContentType.Content = strContentType.ToString() + &quot;; charset=UTF-8&quot;;
  Page.Header.Controls.Add(hmtContentType);
}
else
{
  // Generate xml declaration
  Response.Write(&quot;&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; ?&gt;
&quot;);
}
// Set the page encoding
Response.ContentEncoding = System.Text.Encoding.UTF8;
// Send a Vary header to inform proxy servers that content negotiation is taking place
Response.AddHeader(&quot;Vary&quot;, &quot;Accept&quot;);
</pre><h2>Note</h2><p>When served as <code>application/xhtml+xml</code>, all <code>&lt;style&gt;</code> and <code>&lt;script&gt;</code> in the <abbr
title="eXtensible HyperText Markup Language">XHTML</abbr> document must be marked as <a
href="/2006/11/marking-script-and-style-as-cdata/" title="Article on Marking Script and Style as CDATA">CDATA</a>. Because ASP.NET automatically generates JavaScript, this can be a problem. See <a
href="/2006/11/marking-asp-net-2-0-generated-javascript-as-cdata/" title="Article on Marking ASP.NET 2.0 Generated JavaScript as CDATA">Marking ASP.NET 2.0 Generated JavaScript as CDATA</a> for a workaround.</p> ]]></content:encoded> <wfw:commentRss>http://mattaustin.me.uk/2006/11/serving-the-correct-mime-type-for-xhtml-using-asp-net-2-0/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Marking ASP.NET 2.0 Generated JavaScript as CDATA</title><link>http://mattaustin.me.uk/2006/11/marking-asp-net-2-0-generated-javascript-as-cdata/</link> <comments>http://mattaustin.me.uk/2006/11/marking-asp-net-2-0-generated-javascript-as-cdata/#comments</comments> <pubDate>Tue, 31 Oct 2006 16:00:40 +0000</pubDate> <dc:creator>Matt</dc:creator> <category><![CDATA[asp.net]]></category> <guid
isPermaLink="false">http://mattaustin.me.uk/?p=222</guid> <description><![CDATA[The following code example is a workaround for marking ASP.NET generated JavaScript as CDATA, which is required when serving XHTML ASP.NET 2.0 pages as application/xhtml+xml (see Serving the Correct MIME Type for XHTML using ASP.NET 2.0). Place the following code in your master page: protected override void Render(HtmlTextWriter writer) { StringWriter stwHtml = new StringWriter(); [...]]]></description> <content:encoded><![CDATA[<p>The following code example is a workaround for marking ASP.NET generated JavaScript as <a
href="/2006/11/marking-script-and-style-as-cdata/" title="Article on Marking Script and Style as CDATA">CDATA</a>, which is required when serving <abbr
title="eXtensible HyperText Markup Language">XHTML</abbr> ASP.NET 2.0 pages as <code>application/xhtml+xml</code> (see <a
href="/2006/11/serving-the-correct-mime-type-for-xhtml-using-asp-net-2-0/" title="Article on Serving the Correct MIME Type for XHTML using ASP.NET 2.0">Serving the Correct MIME Type for XHTML using ASP.NET 2.0</a>).</p><p>Place the following code in your master page:</p><pre>
protected override void Render(HtmlTextWriter writer)
{
  StringWriter stwHtml = new StringWriter();
  base.Render(new HtmlTextWriter(stwHtml));
  String strHtml = stwHtml.ToString();
  // Enclose ASP.NET generated client ECMAScript / JavaScript in CDATA Wrapper
  Regex regScriptCDATA = new Regex(&quot;(&lt;script\stype=&quot;text\/....script&quot;&gt;(?:\s)*?)&quot; + &quot;(?:&lt;!--\s)&quot; + &quot;((?:.|
)*?)&quot; + &quot;(?:// --&gt;)&quot; + &quot;((?:\s)*?&lt;\/script&gt;)&quot;);
  String strScriptCDATA = &quot;$1&quot; + &quot;&lt;!--//--&gt;&lt;![CDATA[//&gt;&lt;!--
&quot; + &quot;$2&quot; + &quot;
//--&gt;&lt;!]]&gt;&quot; + &quot;$3&quot;;
  strHtml = regScriptCDATA.Replace(strHtml, strScriptCDATA);
  writer.Write(strHtml);
}
</pre><p></p><p>You may need to add the following at the beginning of your master page code:</p><pre>
using System.IO;
using System.Text.RegularExpressions;
</pre>]]></content:encoded> <wfw:commentRss>http://mattaustin.me.uk/2006/11/marking-asp-net-2-0-generated-javascript-as-cdata/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> </channel> </rss>
