Theme not set in web.config PagesSection

A

Andrew Jocelyn

Hi

When I query the pages section of the web config file it's always an empty
string.

<configuration>
<system.web>
<pages theme="MyTheme" />
</system.web>
</configuration>

I've tried running this code in various page events but I've had no luck.
protected void Page_Load(object sender, EventArgs e)

{

// Get the Web application configuration.

Configuration configuration =
WebConfigurationManager.OpenWebConfiguration("");

// Get the section.

PagesSection pagesSection =
(PagesSection)configuration.GetSection("system.web/pages");

var theme = pagesSection.Theme;

Trace.Write("Current Theme value", theme);

}

Please advise.

Thanks

Andrew
 
A

Andrew Jocelyn

Hi again

I worked out that you need to put a '/' in the constructor, i.e.

WebConfigurationManager.OpenWebConfiguration("/");

On the subject of themes, is it possible to have a fully precompiled site
and still be able to change the theme in the web.config file? I notice that
the precompiled website assembly has the default theme hard coded in. I
tried to exclude the App_Themes folder from the build and add it back in
afterwards but it doesn't work.

I'd like to be able to have a fully precompiled site and be able to change
the theme at runtime. Is that possible?

Thanks
Andrew
 
A

Allen Chen [MSFT]

Hi Andrew,

I think I need to know the following things before answering your question.
Could you clarify them first?

" Is your project a Web Site or a Web Application?

" By saying "precompiled" do you mean you're writing a Web Site and
publishing it with "allow this precompiled site to be updatable" unchecked
or you're using aspnet_compiler tool to precompile the site?

" Do you want to change the theme for one user if, say, he presses a button
on the page? (Editing web.config will affect all users viewing your pages)

If it's possible, please tell me your exact requirement so that I can
understand your scenario better.

Regards,
Allen Chen
Microsoft Online Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

Note: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 2 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions. Issues of this
nature are best handled working with a dedicated Microsoft Support Engineer
by contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
A

Andrew Jocelyn

Hi Allen

My project is a web application and I'm using a web deployment project to
build it. The site is not updateable.

I was hoping to use themes to allow a whole site to change it's appearance.
This might be because:

1. The application is installed to different websites and each website
requires a different appearance
2. The application runs under one website but it's appearence is dictated by
the host name, i.e. you might have a list of domains in IIS and each request
with a different host name requires a different theme.

I hope that makes sense. Are the themes the best option for me or do I need
to rethink my design?

Many thanks
Andrew
 
A

Allen Chen [MSFT]

Hi Andrew,

Thanks for the update.

Quote from Andrew =================================================
1. The application is installed to different websites and each website
requires a different appearance

=================================================

In that case I think we can manually edit the web.config after publishing.
Is there any particular reason that you don't want to do that?

Quote from Andrew =================================================

2. The application runs under one website but it's appearence is dictated
by
the host name, i.e. you might have a list of domains in IIS and each
request
with a different host name requires a different theme.
=================================================

In this case I think we can check the Request.Headers["Host"] and change
the theme of the page in PreInit. This will change the theme for every
request.

From the code in your initial post you're trying to edit the web.config
file via ASP.NET. I could think of one scenario that may use this
technique. That is to provide a web portal for the web site administrator
to edit the config of their web site. Is this your scenario? If not
probably the above way is a better option.

Regards,
Allen Chen
Microsoft Online Support
 
A

Andrew Jocelyn

Hi Allen
In that case I think we can manually edit the web.config after publishing.
Is there any particular reason that you don't want to do that?

I've found that if the web site is precompliled and not updatable then
changing the Theme attribute in the web.config file has no effect. The theme
is hardwired into each page as far as I can tell. The reason we may need to
change the theme is when a customer changes their visual design and we want
to switch the themes from an old one to a new one in the web.config.
In this case I think we can check the Request.Headers["Host"] and change
the theme of the page in PreInit. This will change the theme for every
request.

I think this may be a good option for us. Can you just confirm that the
Theme is not supposed to be updateable from the web.config file once a site
is pre-compiled?

Thanks again
Andrew
 
A

Allen Chen [MSFT]

Hi Andrew,

Thanks for the update. Yes, for a precompiled, read-only web site, if we
set the following settings in web.config:

<pages theme="MyTheme" />

The theme will be hard coded and cannot be changed by editing web.config
after deployment.

If we have to create a read-only web site. I think we can try this to solve
this problem:

In Web.config:

<appSettings>
<add key="pagestheme" value="Theme2"/>
</appSettings>

Aspx.cs:

protected void Page_PreInit(object sender, EventArgs e)
{
string theme = ConfigurationManager.AppSettings["pagestheme"];
this.Theme = theme;
}

If you want to apply the theme for all the pages you can write a base page
class to let your page derive from it.
Could you try the above way to see if it works for you?

Regards,
Allen Chen
Microsoft Online Support
 
A

Allen Chen [MSFT]

Hi Andrew,

Have you tested my suggestion? Can it work?

Regards,
Allen Chen
Microsoft Online Support
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top