Click here to Skip to main content
15,860,972 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Friends,

I need to change Theme dynamically

Here is my code:

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



It works in Local server in MS but when I run in LocalHost it shows like this:

MSIL
Access to the path 'E:\My_Work_Place\Projects - Backup\TolivaultNew\web.config' is denied.


Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.UnauthorizedAccessException: Access to the path 'E:\My_Work_Place\Projects - Backup\TolivaultNew\web.config' is denied.
ASP.NET is not authorized to access the requested resource. Consider granting access rights to the resource to the ASP.NET request identity. ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS 5 or Network Service on IIS 6) that is used if the application is not impersonating. If the application is impersonating via <identity impersonate="true"/>, the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user.
To grant ASP.NET access to a file, right-click the file in Explorer, choose "Properties" and select the Security tab. Click "Add" to add the appropriate user or group. Highlight the ASP.NET account, and check the boxes for the desired access.
Source Error:

Line 173:        section.Theme = "Green";
Line 174:        section.StyleSheetTheme = "Green";
Line 175:        config.Save();


Any solutions? :)
Posted
Updated 4-Feb-11 1:59am
v2

1 solution

you need to give your application pool identity write access to web.config.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900