Question

I have the following config that I would like to remove from web config and only enforce in code for a certain page 'Page1.aspx', else the configuration would apply across all pages.

How would I specify this configuration or enforce it through code, so it applies to only Page1.aspx?

<system.web>
  <browserCaps>
    <case>
        RequiresControlStateInSession=true
    </case>
  </browserCaps>
</system.web>
Was it helpful?

Solution

I just found a way to mention configuration on a page basis, so the configuration only applies to that page.

Just include any specific configuration under Location element that you would like to apply to a single page. Keep the following points in mind when using this approach.

  • Set an appropriate value for the path attribute of location element. Path can be a relative path.
  • The location element must be outside the system.web and system.webserver and any other sections within web config

Location is a section by itself in a web.config file.

In my case the following worked, where I specified a Location section for the single page for which I wanted to specify special configuration:

<?xml version="1.0"?>
<configuration>
//all sections in web config go here. Put the Location elements always 
// at end of your web config file
  <location path="Page1.aspx">
   <system.web>
    <browserCaps>
     <case>
       RequiresControlStateInSession=true
     </case>
    </browserCaps>
   </system.web>
  </location>
</configuration>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top