ASP.NET Themes and required Head objects
Hmmm… I'm creating an RSS Feed page on one of my new apps I'm working on (yet another Blog <g>)…
The site uses themes but when I'm generating the Rss.aspx page which looks like this:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Rss.aspx.cs"
Inherits="Westwind.WebLog.Rss"
EnableTheming="false" EnableSessionState="false" %>
But ASP.NET complains about the fact that the header is missing:
Exception Details: System.InvalidOperationException: Using themed css files requires a header control on the page. (e.g. <head runat="server" />).
This even though EnableTheming is off for the page.
In order to get this to work I have to drop in the HTML header like this:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Rss.aspx.cs"
Inherits="Westwind.WebLog.Rss"
EnableTheming="false" EnableSessionState="false" %>
<head runat="server" id="Header" />
It doesn't matter for my RSS page since the XML is generated directly into the Response.OutputStream(), but this adds a little unneeded overhead into the page. But if you had a page that wanted to use the ASPX content to generate some non-HTML output that doesn't include a header you'd have to explicitly set the header visible=false I guess.
So to generate a page that shows just your text and no header:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebLog.WebForm1" %>
<head runat="server" visible=false/>This is a test
Other Posts you might also like
- Adding minimal OWIN Identity Authentication to an Existing ASP.NET MVC Application
- Resolving Paths To Server Relative Paths in .NET Code
- Map Physical Paths with an HttpContext.MapPath() Extension Method in ASP.NET
- Back to Basics: Rewriting a URL in ASP.NET Core
- Getting the Client IP Address in ASP.NET Core
The Voices of Reason
# re: ASP.NET Themes and required Head objects
# re: ASP.NET Themes and required Head objects
No doubt and normally I would a handler but the site needs to match URLs as much as possible so hence the ASPX page. Hmmm... I guess I can stuff it into my Url Rewriting handler as well.
In either case this is isn't going to matter all that much since the RSS page will cached heavily anyway.
The main point is though that EnableTheming false should really remove this header requirement.
# re: ASP.NET Themes and required Head objects
<location path="CMS">
<system.web>
<pages theme="" />
</system.web>
</location>
I'm doing this in a few MCMS projects.
# re: ASP.NET Themes and required Head objects
# re: ASP.NET Themes and required Head objects
# re: ASP.NET Themes and required Head objects
Worked great... I ran into this issue using a page with an XML doctype feeding an AJAX callback...
Appreciate the help!
# re: ASP.NET Themes and required Head objects
the page directive Theme="" works fine for me.
# re: ASP.NET Themes and required Head objects
Doesnt make much sense to me that theme="" does the job when EnableTheming=false (which is docummented) doesnt.
# re: ASP.NET Themes and required Head objects
# re: ASP.NET Themes and required Head objects
# re: ASP.NET Themes and required Head objects
# re: ASP.NET Themes and required Head objects
# re: ASP.NET Themes and required Head objects
Mark Zak's snippet worked for me.
# re: ASP.NET Themes and required Head objects
EnableTheming="false" StylesheetTheme=""
The hidden <head> tag is not needed then.
# re: ASP.NET Themes and required Head objects
And the last one.... from atx... even better.
# re: ASP.NET Themes and required Head objects
# re: ASP.NET Themes and required Head objects
# re: ASP.NET Themes and required Head objects
I was using Theme in my application and instead of putting in all pages , I used it through web.config file .
<pages theme="Default">
But for some of my pages the application was throwing following Exception
System.InvalidOperationException: Using themed css files requires a header control on the page. (e.g. <head runat="server" />).
at System.Web.UI.PageTheme.SetStyleSheet()
at System.Web.UI.Page.OnInit(EventArgs e)
at System.Web.UI.Control.InitRecursive(Control namingContainer)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
Which means that all my pages should have runat="server" in the <head> tag, like the following:
<head runat="server"></head>
But for some pages it was difficult to use the <head> tag like the pages for not rendering 'text/html' content and as a result of which it was throwing Exception.
So here is the solution
Set EnableTheming = "False" StylesheetTheme="" Theme="" at the specific page level in the @Page attribute.
http://www.mindfiresolutions.com/
# re: ASP.NET Themes and required Head objects
Also check out the new ASP.NET 2.0 RSS toolkit, which looks really sweet: http://weblogs.asp.net/scottgu/archive/2006/02/22/438738.aspx