4

I am using MVC Areas. Within each area I have a views section and in that a web config that contains the following:

<configSections>
  <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
    <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
    <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
  </sectionGroup>
</configSections>

<system.web.webPages.razor>
  <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
  <pages pageBaseType="System.Web.Mvc.WebViewPage">
    <namespaces>
      <add namespace="System.Web.Mvc" />
      <add namespace="System.Web.Mvc.Ajax" />
      <add namespace="System.Web.Mvc.Html" />
      <add namespace="System.Web.Routing" /> ... more namespaces common to all views ...
    </namespaces>
  </pages>
</system.web.webPages.razor>

I always try to not repeat my code so I am wondering. Can I take the above out of the web.configs in each area and add to the top level web.config. I tried and it seems to work. But is it an okay thing to do?

KyleMit
  • 30,350
  • 66
  • 462
  • 664
Samantha J T Star
  • 30,952
  • 84
  • 245
  • 427

1 Answers1

2

Yes, you can.

However, it will break any non-MVC Razor pages in your site.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
  • Okay this is a big problem. What do you mean by "break"? I believe all my web pages use Razor. Should I really repeat the same section in each web.config ? – Samantha J T Star Nov 18 '11 at 13:31
  • @Melissa: It will break **non-MVC** Razor pages. This configuration tells all Razor pages to inherit the MVC base type. If you have a normal Razor page (not an MVC view), putting this config in the root will apply to it as well. – SLaks Nov 18 '11 at 14:52
  • If your app is purely MVC, it's not a problem. – SLaks Nov 18 '11 at 14:53
  • If you only put the `` in the root, it won't break anything. – SLaks Nov 18 '11 at 14:53
  • @SLaks I believe what you suggest is impossible since `` is a child of ``, and that one has a compulsory attribute `pageBaseType` which is the core of this answer. – tsemer Feb 19 '14 at 09:09