Unrecognized configuration section system.web.webPages.razor Error

Unrecognized configuration section system.web.webPages.razor Error is one error caused due to some inappropriate configuration in web.config file. Use these steps to solve this error.

Coding is fun till you get bit by a bug after which it starts making fun of you. The situation worsens when the error is coming from some other place. And today it happened with me. Got the following error just when I thought everything was correctly done and let's run the project.2015-05-19_165459 Parser Error Unrecognized configuration section system.web.webPages.razor Error

Weirdo! Some of these errors are really the doomsday of the savior. Having pulled half of my hair (not literally :P) I was really running out of time for something which was needed to be setup quickly.

What's the solution?

The problem is caused because the razor section that the error is referring to is not identified by the Razor Engine. That's because:

  1. Either you added the razor section to a wrong web.config file (remember there is a web.config file for your project and other one for views folder)
  2. You forgot to add some importantlines to your web.config which could tell the razor engine to do the honors.

I tried too many things when I finally found a solution. Just add the following lines of code to the configSections tag of your web.config file and things should be OK in no time.

<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>

Hope the little snippet helps.

Get updates directly in your inbox

My collection of ideas, thoughts, stories or anything straight from my heart.

Subscribe to Anshul Sojatia

Please provide your email address to subscribe or Login with Twitter to engage in conversation.