Theme not set in web.config PagesSection

Discussion in 'ASP .Net' started by Andrew Jocelyn, Mar 5, 2009.

  1. 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
     
    Andrew Jocelyn, Mar 5, 2009
    #1
    1. Advertising

  2. 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
     
    Andrew Jocelyn, Mar 5, 2009
    #2
    1. Advertising

  3. 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:
    .

    ==================================================
    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.
     
    Allen Chen [MSFT], Mar 6, 2009
    #3
  4. 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
     
    Andrew Jocelyn, Mar 6, 2009
    #4
  5. 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
     
    Allen Chen [MSFT], Mar 9, 2009
    #5
  6. 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
     
    Andrew Jocelyn, Mar 10, 2009
    #6
  7. 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
     
    Allen Chen [MSFT], Mar 11, 2009
    #7
  8. Hi Andrew,

    Have you tested my suggestion? Can it work?

    Regards,
    Allen Chen
    Microsoft Online Support
     
    Allen Chen [MSFT], Mar 13, 2009
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Benny Ng
    Replies:
    9
    Views:
    10,246
    Benny Ng
    Oct 13, 2005
  2. Sachin
    Replies:
    3
    Views:
    878
    Alan Silver
    Mar 1, 2006
  3. vikramp
    Replies:
    0
    Views:
    890
    vikramp
    Oct 31, 2006
  4. CSharpner
    Replies:
    0
    Views:
    1,141
    CSharpner
    Apr 9, 2007
  5. Seth Rasmussen
    Replies:
    3
    Views:
    213
    Seth Rasmussen
    Sep 17, 2005
Loading...

Share This Page