Change Theme in web.config dynamically in Shared Hosting

V

vikramp

Hi,

I am storing theme in web.config using <pages theme="mytheme"/>.
I am then using the following code to read it from my webpage:

Configuration config =
WebConfigurationManager.OpenWebConfiguration("~");
PagesSection section =
(PagesSection)config.GetSection("system.web/pages");
string currenttheme = section.Theme;

and then to change the theme and save it back in web.config, I am using
the following code:

Configuration config =
WebConfigurationManager.OpenWebConfiguration("~");
PagesSection section =
(PagesSection)config.GetSection("system.web/pages");
section.Theme = newtheme;
config.Save();

This works perfectly fine on my machine. But when I upload it on my
website, it throws security exception. I am hosting my site on godaddy
with Shared Hosting.

I then made changes in the code for reading the theme: Instead of
saying:

Configuration config =
WebConfigurationManager.OpenWebConfiguration("~");
PagesSection section =
(PagesSection)config.GetSection("system.web/pages");

I changed it to:
PagesSection section =
(PagesSection)WebConfigurationManager.GetSection("system.web/pages");

This worked. But when it comes to saving theme back to web.config, I
get an error "The configuration is read only".

I guess it is because I am on shared hosting and aspnet or
NetworkService account do not have permission to modify web.config,

Is that the reason? or is it something else? Is there any workaround?

Appreciate your help.

Thanks.
 

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

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top