locked
Unrecognized configuration section system.web.webPages.razor. RRS feed

  • Question

  • User2001833234 posted

    Could someone Help,  I watched a youtube video, where the person showed how to create a Custom HTML Helper.  He aslo showed that you can add a section to your Web.Config file of your MVC application and then the HTML Helper would be available to all views without the need for a @using statement.  I am able to create my own HTML helper functions etc but I can only get them to work if I use the @using statement in my view.

    This is the Web.Config entry that the guy used and it worked for him.  I get this error  "Unrecognized configuration section system.web.webPages.razor."  Note: I'm using VS 2012.

    I added this code right after the <ConfigSections>  Would anyone know what I'm doing wrong.  It would be cool to create an html helper and not use the @using statement all the time.

    Thanks Dave.

      <system.web.webPages.razor>
        <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" />
            <add namespace="MVCDemoEF.CustomHtmlHelpers" />
          </namespaces>
        </pages>
      </system.web.webPages.razor>
    Friday, April 4, 2014 11:50 AM

Answers

  • User-812053960 posted

    It looks okay assuming that MVCDemoEF.CustomHtmlHelpers namespace is reachable but that isn't the issue the error is reporting anyway.

    here's my web.config (note its the one in the Views folder, not the one in the project root)

    <configuration>
      <configSections>
        <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
          <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
          <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.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=5.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.Optimization"/>
            <add namespace="System.Web.Routing" />
            <add namespace="WebApplication3" />
          </namespaces>
        </pages>
      </system.web.webPages.razor>
    
      <appSettings>
        <add key="webpages:Enabled" value="false" />
      </appSettings>
    
      <system.webServer>
        <handlers>
          <remove name="BlockViewHandler"/>
          <add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
        </handlers>
      </system.webServer>
    </configuration>

    make sure your configSections contains at least the pages line (in bold in my example) so you can use the pages tag.  I also use the host so that's why host is defined in configSections too.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, April 4, 2014 12:28 PM

All replies

  • User-812053960 posted

    It looks okay assuming that MVCDemoEF.CustomHtmlHelpers namespace is reachable but that isn't the issue the error is reporting anyway.

    here's my web.config (note its the one in the Views folder, not the one in the project root)

    <configuration>
      <configSections>
        <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
          <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
          <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.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=5.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.Optimization"/>
            <add namespace="System.Web.Routing" />
            <add namespace="WebApplication3" />
          </namespaces>
        </pages>
      </system.web.webPages.razor>
    
      <appSettings>
        <add key="webpages:Enabled" value="false" />
      </appSettings>
    
      <system.webServer>
        <handlers>
          <remove name="BlockViewHandler"/>
          <add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
        </handlers>
      </system.webServer>
    </configuration>

    make sure your configSections contains at least the pages line (in bold in my example) so you can use the pages tag.  I also use the host so that's why host is defined in configSections too.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, April 4, 2014 12:28 PM
  • User2001833234 posted

    Thanks Russrigues:  I didn't realize that their even was a Views/Web.config file.  I was adding it to the Solution web.config.

    Thanks again.

    Friday, April 4, 2014 12:38 PM