Tarik
Tarik

Reputation: 81791

Page Specific Configuration in Web.Config

I do wonder whether there is a way to set page-based configuration in web.config? Lets say I have Default.aspx and Product.aspx and I want to define different configurations such as EnableViewState etc. but in web.config rather than in page itself.

So you may ask why? Please do understand this is how it should be.

Upvotes: 2

Views: 2925

Answers (2)

jrummell
jrummell

Reputation: 43097

You can use the location tag in web.config to specify different settings for different paths.

<configuration>
   <location path="Logon.aspx">
      <system.web>
         <authorization>
            <allow users="?"/>
         </authorization>
      </system.web>
   </location>

   <location path="UploadPage.aspx">
     <system.web>
       <httpRuntime maxRequestLength="128"/>
    </system.web>
  </location>
</configuration>

Upvotes: 8

Nathan Taylor
Nathan Taylor

Reputation: 24606

I'm not sure if this is the only solution, but placing the page in its own folder and defining a web.config in that folder would allow you to achieve per-page configuration. Combine this with custom routing and it wouldn't be completely horrible.

Upvotes: 2

Related Questions